Safe Haskell | None |
---|---|
Language | Haskell2010 |
Internal functions that are used in the SMTP protocol, you may need these module in case if you want to implement additional functionality that does not exist in the Network.HaskellNet.SMTP.
Example.
One example could be sending multiple emails over the same stream
in order to use that you may want to use RSET
command, so you can implement:
import Network.HaskellNet.SMTP.Internal resetConnection :: SMTPConnection -> IO () resetConnection conn = do (code, _) <-sendCommand
connRSET
unless
(code == 250) $throwIO
$UnexpectedReply
RSET
[250] code ""
Synopsis
- data SMTPConnection = SMTPC {
- bsstream :: !BSStream
- _response :: ![ByteString]
- data Command
- data SMTPException
- type ReplyCode = Int
- tryCommand :: SMTPConnection -> Command -> Int -> [ReplyCode] -> IO ByteString
- parseResponse :: BSStream -> IO (ReplyCode, ByteString)
- sendCommand :: SMTPConnection -> Command -> IO (ReplyCode, ByteString)
- sendMailData :: Address -> [Address] -> ByteString -> SMTPConnection -> IO ()
- closeSMTP :: SMTPConnection -> IO ()
- gracefullyCloseSMTP :: SMTPConnection -> IO ()
- quitSMTP :: SMTPConnection -> IO ()
- data Address = Address {
- addressName :: Maybe Text
- addressEmail :: Text
Documentation
data SMTPConnection Source #
All communication with server is done using SMTPConnection
value.
SMTP commands.
Supports basic and extended SMTP protocol without TLS support.
For each command we provide list of the expected reply codes that happens in success and failure cases respectively.
HELO Text | The Success: 250 Failure: 504, 550 |
EHLO Text |
Success: 250 Failure: 502, 504, 550 |
MAIL Text |
Success: 250 Failure: 451, 452, 455, 503, 550, 552, 553, 555 |
RCPT Text | The Success: 250 251 Failure: 450 451 452 455 503 550 551 552 553 555 |
DATA ByteString | With the Success: 250, 354 Failure: 450 451 452 503 550 552 554 Client just sends data and after receiving 354 starts streaming email, terminating transfer by
sending |
EXPN Text |
Success: 250 252 Failure: 502 504 550 |
VRFY Text |
Success: 250 251 252 Failure: 502 504 550 551 553 |
HELP Text | With the Success: 211 214 Failure: 502 504 |
AUTH AuthType UserName Password | Authorization support |
NOOP |
Success: 250 |
RSET |
Success: 250 |
QUIT |
Success: 221 |
data SMTPException Source #
Exceptions that can happen during communication.
UnexpectedReply Command [ReplyCode] ReplyCode ByteString | Reply code was not in the list of expected.
|
NotConfirmed ReplyCode ByteString | The server didn't accept the start of the message delivery |
AuthNegotiationFailed ReplyCode ByteString | The server does not support current authentication method |
NoRecipients Mail | Can't send email because no recipients were specified. |
UnexpectedGreeting ReplyCode | Received an unexpected greeting from the server. |
Instances
Show SMTPException Source # | |
Defined in Network.HaskellNet.SMTP.Internal showsPrec :: Int -> SMTPException -> ShowS # show :: SMTPException -> String # showList :: [SMTPException] -> ShowS # | |
Exception SMTPException Source # | |
Defined in Network.HaskellNet.SMTP.Internal |
:: SMTPConnection | Connection |
-> Command | Supported command |
-> Int | Number of allowed retries |
-> [ReplyCode] | List of accepted codes |
-> IO ByteString | Resulting data |
Safe wrapper for running a client command over the SMTP connection.
Note on current behavior
We allow the command to fail several times, retry happens in case if we have received unexpected status code. In this case message will be sent again. However in case of other synchronous or asynchronous exceptions there will be no retries.
It case if number of retries were exceeded connection will be closed automatically.
The behaviors in notes will likely be changed in the future and should not be relied upon, see issues 76, 77.
parseResponse :: BSStream -> IO (ReplyCode, ByteString) Source #
Read response from the stream. Response consists of the code and one or more lines of data.
In case if it's not the last line of reply the code is followed
by the -
sign. We return the code and all the data with the code
stripped.
Eg.:
"250-8BITMIME\r" "250-PIPELINING\r" "250-SIZE 42991616\r" "250-AUTH LOGIN PLAIN XOAUTH2\r" "250-DSN\r" "250 ENHANCEDSTATUSCODES\r"
Returns:
(250, "8BITMIME\nPIPELININGnSIZE 42991616\nAUTH LOGIN PLAIN XOAUTH2\nDSN\nENHANCEDSTATUSCODES")
Throws SMTPException
.
sendCommand :: SMTPConnection -> Command -> IO (ReplyCode, ByteString) Source #
Sends a Command
to the server. Function that performs all the logic
for sending messages. Throws an exception if something goes wrong.
Throws SMTPException
.
:: Address | sender mail |
-> [Address] | receivers |
-> ByteString | data |
-> SMTPConnection | |
-> IO () |
Sends a mail to the server.
Throws SMTPException
.
closeSMTP :: SMTPConnection -> IO () Source #
Terminates the connection. Quit
command is not send in this case.
It's safe to issue this command at any time if the connection is still
open.
gracefullyCloseSMTP :: SMTPConnection -> IO () Source #
Gracefully closes SMTP connection. Connection should be in available
state. First it sends quit command and then closes connection itself.
Connection should not be used after this command exits (even if it exits with an exception).
This command may throw an exception in case of network failure or
protocol failure when sending QUIT
command. If it happens connection
nevertheless is closed.
Since: 0.6
quitSMTP :: SMTPConnection -> IO () Source #
Sends quit to the server. Connection must be terminated afterwards, i.e. it's not allowed to issue any command on this connection.
Reexports
Address | |
|
Instances
Eq Address | |
Show Address | |
IsString Address | |
Defined in Network.Mail.Mime fromString :: String -> Address # | |
Generic Address | |
type Rep Address | |
Defined in Network.Mail.Mime type Rep Address = D1 ('MetaData "Address" "Network.Mail.Mime" "mime-mail-0.5.1-Lei8jtK8iHw47bF11YUI3Q" 'False) (C1 ('MetaCons "Address" 'PrefixI 'True) (S1 ('MetaSel ('Just "addressName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "addressEmail") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) |