HaskellNet-0.2.4: example/smtpMimeMail.hs
--import qualified Data.ByteString.Lazy.UTF8 as LU
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString as S
import Control.Monad
import qualified Network.HaskellNet.SMTP as HN
import qualified Data.Text.Lazy as LT
--import qualified Data.Text.Lazy.Encoding as LT
{-
An example of how to use Network.HaskellNet with the mime-mail package.
Useful if you don't have sendmail installed and want to use
mime-mail.
nb: you need to cabal install mime-mail to run this example.
(I didn't want to include mime-mail as a dependency of Network.HaskellNet.)
-}
-- substitute your isp's smtp server here
smtpServer = "outmail.f2s.com"
-- subtitute your address here
toAddress = "wrwills@gmail.com"
{-
sendMimeMail :: String -> String -> LT.Text -> LT.Text -> [(String, FilePath)] -> IO ()
sendMimeMail to from subject plainBody htmlBody attachments = do
myMail <- simpleMail to from subject plainBody htmlBody attachments
con <- HN.connectSMTP smtpServer
renderedMail <- renderMail' myMail
HN.sendMail from [to] (lazyToStrict renderedMail) con
HN.closeSMTP con
-}
-- haskellNet uses strict bytestrings
-- TODO: look at making haskellnet lazy
lazyToStrict = S.concat . B.toChunks
main = do
con <- HN.connectSMTP smtpServer
HN.sendMimeMail toAddress
"haskellnet@test.com"
"Testing "
(LT.pack $ unlines [
"With some Li Bai to show we can do unicode"
, "舉頭望明月"
, "低頭思故鄉"
])
(LT.pack "<html><body>低頭思故鄉</body></html>" )
[("application/pdf","/tmp/cv.pdf")]
con
HN.closeSMTP con
-- [("application/pdf","/tmp/cv.pdf"), ("image/jpeg", "/tmp/img.jpg")]