SMTPClient-0.3: A simple SMTP clientSource codeContentsIndex
Network.SMTP.ClientSession
Description
A pure SMTP client state machine.
Synopsis
smtpClientSession :: String -> [Message] -> SMTPState
data SMTPState = SMTPState {
smtpOutQueue :: [String]
smtpReceive :: String -> SMTPState -> SMTPState
smtpSuccess :: Bool
smtpFailure :: Maybe String
smtpStatuses :: [Maybe SmtpReply]
}
data SmtpReply = Reply SmtpCode [String]
data SmtpCode = Code SuccessCode Category Int
data SuccessCode
= Unused0
| PreliminarySuccess
| Success
| IntermediateSuccess
| TransientFailure
| PermanentFailure
data Category
= Syntax
| Information
| Connection
| Unspecified3
| Unspecified4
| MailSystem
data Message = Message [Field] String
data Field
= OptionalField String String
| From [NameAddr]
| Sender NameAddr
| ReturnPath String
| ReplyTo [NameAddr]
| To [NameAddr]
| Cc [NameAddr]
| Bcc [NameAddr]
| MessageID String
| InReplyTo [String]
| References [String]
| Subject String
| Comments String
| Keywords [[String]]
| Date CalendarTime
| ResentDate CalendarTime
| ResentFrom [NameAddr]
| ResentSender NameAddr
| ResentTo [NameAddr]
| ResentCc [NameAddr]
| ResentBcc [NameAddr]
| ResentMessageID String
| ResentReplyTo [NameAddr]
| Received ([(String, String)], CalendarTime)
| ObsReceived [(String, String)]
data NameAddr = NameAddr {
nameAddr_name :: Maybe String
nameAddr_addr :: String
}
Documentation
smtpClientSessionSource
:: StringDomain name used in EHLO command
-> [Message]List of messges to send
-> SMTPState
Construct a pure state machine for an SMTP client session. Caller must handle I/O. The message body may use either "\n" or "\r\n" for an end-of-line marker.
data SMTPState Source
Constructors
SMTPState
smtpOutQueue :: [String]Step 1. Caller must output any lines queued up in this list. They do not have end-of-line characters, so the caller must add "\r\n" on the end (as required by RFC2821 - not just "\n").
smtpReceive :: String -> SMTPState -> SMTPStateStep 2. When sends are completed, the caller should wait for a line from the SMTP server, strip the "\n" end-of-line characters, and pass the line to this function for processing.
smtpSuccess :: BoolStep 3. Check if this is True, which indicates that the SMTP session has completed successfully and there is no more work to do.
smtpFailure :: Maybe StringStep 4. Check if this is Just err, which indicates that a protocol error has occurred, and that the caller must terminate the session.
smtpStatuses :: [Maybe SmtpReply]A list containing a failure status for each message that has been sent so far, where each element corresponds to one in the list of messages. If the SMTP session fails part-way through, this list is likely to be shorter than the input messages list. Nothing means success, and Just x is a failure status returned by the SMTP server.
data SmtpReply Source

An SMTP reply is a three-digit return code plus some waste of bandwidth called "comments". This is what the list of strings is for; one string per line in the reply. show will append an "\r\n" end-of-line marker to each entry in that list, so that the resulting string is ready to be sent back to the peer.

Here is an example:

*Rfc2821> print $ Reply (Code Success MailSystem 0) ["worked", "like", "a charm" ] 250-worked 250-like 250 a charm

If the message is [], you'll get a really helpful default text.

Constructors
Reply SmtpCode [String]
show/hide Instances
data SmtpCode Source
Constructors
Code SuccessCode Category Int
show/hide Instances
data SuccessCode Source
Constructors
Unused0
PreliminarySuccess
Success
IntermediateSuccess
TransientFailure
PermanentFailure
show/hide Instances
data Category Source
Constructors
Syntax
Information
Connection
Unspecified3
Unspecified4
MailSystem
show/hide Instances
data Message Source
This data type repesents a parsed Internet Message as defined in this RFC. It consists of an arbitrary number of header lines, represented in the Field data type, and a message body, which may be empty.
Constructors
Message [Field] String
show/hide Instances
data Field Source
This data type represents any of the header fields defined in this RFC. Each of the various instances contains with the return value of the corresponding parser.
Constructors
OptionalField String String
From [NameAddr]
Sender NameAddr
ReturnPath String
ReplyTo [NameAddr]
To [NameAddr]
Cc [NameAddr]
Bcc [NameAddr]
MessageID String
InReplyTo [String]
References [String]
Subject String
Comments String
Keywords [[String]]
Date CalendarTime
ResentDate CalendarTime
ResentFrom [NameAddr]
ResentSender NameAddr
ResentTo [NameAddr]
ResentCc [NameAddr]
ResentBcc [NameAddr]
ResentMessageID String
ResentReplyTo [NameAddr]
Received ([(String, String)], CalendarTime)
ObsReceived [(String, String)]
show/hide Instances
data NameAddr Source
A NameAddr is composed of an optional realname a mandatory e-mail address.
Constructors
NameAddr
nameAddr_name :: Maybe String
nameAddr_addr :: String
show/hide Instances
Produced by Haddock version 2.6.0