packages feed

smtp-mail 0.1.4.5 → 0.1.4.6

raw patch · 3 files changed

+54/−18 lines, 3 filesdep ~bytestringnew-uploader

Dependency ranges changed: bytestring

Files

LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2012, Jason Hickner+Copyright (c) 2012-2016, Jason Hickner, Matt Parsons  All rights reserved. 
Network/Mail/SMTP.hs view
@@ -1,10 +1,13 @@-{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, RecordWildCards #-}+{-# LANGUAGE OverloadedStrings, RecordWildCards, ScopedTypeVariables #-}+ module Network.Mail.SMTP     ( -- * Main interface       sendMail     , sendMail'     , sendMailWithLogin     , sendMailWithLogin'+    , sendMailWithSender+    , sendMailWithSender'     , simpleMail     , plainTextPart     , htmlPart@@ -23,12 +26,14 @@       -- * Establishing Connection     , connectSMTP     , connectSMTP'+    , connectSMTPWithHostName        -- * Operation to a Connection     , sendCommand     , login     , closeSMTP     , renderAndSend+    , renderAndSendFrom     )     where @@ -63,15 +68,25 @@ -- | Connect to an SMTP server with the specified host and default port (25) connectSMTP :: HostName     -- ^ name of the server             -> IO SMTPConnection-connectSMTP = flip connectSMTP' 25+connectSMTP hostname = connectSMTP' hostname 25  -- | Connect to an SMTP server with the specified host and port connectSMTP' :: HostName     -- ^ name of the server-                -> PortNumber -- ^ port number-                -> IO SMTPConnection+             -> PortNumber -- ^ port number+             -> IO SMTPConnection connectSMTP' hostname port =-    connectTo hostname (PortNumber port) >>= connectStream+    connectTo hostname (PortNumber port) >>= connectStream getHostName ++-- | Connect to an SMTP server with the specified host and port+connectSMTPWithHostName :: HostName     -- ^ name of the server+                        -> PortNumber -- ^ port number+                        -> IO String -- ^ Returns the host name to use to send from+                        -> IO SMTPConnection+connectSMTPWithHostName hostname port getMailHostName =+    connectTo hostname (PortNumber port) >>= connectStream getMailHostName++ -- | Attemp to send a 'Command' to the SMTP server once tryOnce :: SMTPConnection -> Command -> ReplyCode -> IO ByteString tryOnce = tryCommand 1@@ -100,13 +115,13 @@       else return (code, msg)  -- | Create an 'SMTPConnection' from an already connected Handle-connectStream :: Handle -> IO SMTPConnection-connectStream st = do+connectStream :: IO String -> Handle -> IO SMTPConnection+connectStream getMailHostName st = do     (code1, _) <- parseResponse st     unless (code1 == 220) $ do         hClose st         fail "cannot connect to the server"-    senderHost <- getHostName+    senderHost <- getMailHostName     (code, initialMsg) <- tryCommandNoFail 3 (SMTPC st []) (EHLO $ B8.pack senderHost) 250     if code == 250       then return (SMTPC st (tail $ B8.lines initialMsg))@@ -197,7 +212,7 @@ closeSMTP :: SMTPConnection -> IO () closeSMTP c@(SMTPC conn _) = sendCommand c QUIT >> hClose conn --- | Sends a rendered mail to the server. +-- | Sends a rendered mail to the server. sendRenderedMail :: ByteString   -- ^ sender mail             -> [ByteString] -- ^ receivers             -> ByteString   -- ^ data@@ -215,7 +230,7 @@ renderAndSend conn mail@Mail{..} = do     rendered <- lazyToStrict `fmap` renderMail' mail     sendRenderedMail from to rendered conn-  where enc  = encodeUtf8 . addressEmail +  where enc  = encodeUtf8 . addressEmail         from = enc mailFrom         to   = map enc mailTo @@ -249,6 +264,27 @@   renderAndSend con mail   closeSMTP con +-- | Send a 'Mail' with a given sender.+sendMailWithSender :: ByteString -> HostName -> Mail -> IO ()+sendMailWithSender sender host mail = do+    con <- connectSMTP host+    renderAndSendFrom sender con mail+    closeSMTP con++-- | Send a 'Mail' with a given sender.+sendMailWithSender' :: ByteString -> HostName -> PortNumber -> Mail -> IO ()+sendMailWithSender' sender host port mail = do+    con <- connectSMTP' host port+    renderAndSendFrom sender con mail+    closeSMTP con++renderAndSendFrom :: ByteString -> SMTPConnection -> Mail -> IO ()+renderAndSendFrom sender conn mail@Mail{..} = do+    rendered <- BL.toStrict `fmap` renderMail' mail+    sendRenderedMail sender to rendered conn+  where enc  = encodeUtf8 . addressEmail+        to   = map enc mailTo+ -- | A convenience function that sends 'AUTH' 'LOGIN' to the server login :: SMTPConnection -> UserName -> Password -> IO (ReplyCode, ByteString) login con user pass = sendCommand con (AUTH LOGIN user pass)@@ -273,21 +309,21 @@  -- | Construct a plain text 'Part' plainTextPart :: TL.Text -> Part-plainTextPart = Part "text/plain; charset=utf-8" +plainTextPart = Part "text/plain; charset=utf-8"               QuotedPrintableText Nothing [] . TL.encodeUtf8  -- | Construct an html 'Part' htmlPart :: TL.Text -> Part-htmlPart = Part "text/html; charset=utf-8" +htmlPart = Part "text/html; charset=utf-8"              QuotedPrintableText Nothing [] . TL.encodeUtf8  -- | Construct a file attachment 'Part' filePart :: T.Text -- ^ content type-         -> FilePath -- ^ path to file +         -> FilePath -- ^ path to file          -> IO Part filePart ct fp = do     content <- BL.readFile fp-    return $ Part ct Base64 (Just $ T.pack (takeFileName fp)) [] content +    return $ Part ct Base64 (Just $ T.pack (takeFileName fp)) [] content  lazyToStrict :: BL.ByteString -> B.ByteString lazyToStrict = B.concat . BL.toChunks
smtp-mail.cabal view
@@ -2,14 +2,14 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                smtp-mail-version:             0.1.4.5+version:             0.1.4.6 synopsis:            Simple email sending via SMTP -- description: homepage:            http://github.com/jhickner/smtp-mail license:             BSD3 license-file:        LICENSE-author:              Jason Hickner-maintainer:          jhickner@gmail.com+author:              Jason Hickner, Matt Parsons+maintainer:          parsonsmatt@gmail.com -- copyright: category:            Network build-type:          Simple