SMTPClient-1.0.3: A simple SMTP client library

Network.SMTP.ClientSession

Description

A pure SMTP client state machine.

Data structures for representing SMTP status codes and email messages are re-exported here from Text.ParserCombinators.Parsec.Rfc2821 and Text.ParserCombinators.Parsec.Rfc2822 in the hsemail package.

Synopsis

Documentation

smtpClientSessionSource

Arguments

:: String

Domain 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" as an end-of-line marker.

data SMTPState Source

Constructors

SMTPState 

Fields

smtpOutQueue :: [String]

Step 1. Caller must send any lines queued up in this list to the SMTP server. They do not have end-of-line characters, so you must add "\r\n" on the end (both characters are required by RFC2821 - do not just send "\n").

smtpSuccess :: Bool

Step 2. Check if this is True, which indicates that the SMTP session has completed successfully and there is no more work to do.

smtpFailure :: Maybe String

Step 3. Check if this is Just err, which indicates that a protocol error has occurred, and that the caller must terminate the session.

smtpReceive :: String -> SMTPState -> SMTPState

Step 4. The caller should wait for a line from the SMTP server, strip the "\r\n" end-of-line characters, and pass the stripped line to this function for processing. Go to step 1.

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 does not complete successfully, then this list is likely to be shorter than the input messages list. When smtpSuccess is true, this list is guaranteed to be the same length as the list of input messages. Nothing means success, and Just x is a failure status returned by the SMTP server.

data SmtpReply

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] 

Instances

data SmtpCode

Instances

data GenericMessage a

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] a 

Instances

data Field

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.

Instances

data NameAddr

A NameAddr is composed of an optional realname a mandatory e-mail address.

Instances