<div dir="ltr">Forgot to include the header and imported modules in my last message:<div><br></div><div><div><font face="monospace, monospace" size="1"><b>{-# LANGUAGE OverloadedStrings #-}</b></font></div><div><font face="monospace, monospace" size="1"><b><br></b></font></div><div><font face="monospace, monospace" size="1"><b>module Main where</b></font></div><div><font face="monospace, monospace" size="1"><b><br></b></font></div><div><font face="monospace, monospace" size="1"><b>import Network.HaskellNet.SMTP</b></font></div><div><font face="monospace, monospace" size="1"><b>import Network.HaskellNet.SMTP.SSL</b></font></div></div><div><br></div><div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b>main :: IO ()</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b>main = doSMTPSTARTTLSWithSettings "<a href="http://smtp.gmail.com/" target="_blank">smtp.gmail.com</a>" settings $ \conn -> do</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> if authSucceed</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> then do</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> putStrLn "Sending email..."</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> sendPlainTextMail "<a href="mailto:recipient@somewhere.com" target="_blank">recipient@somewhere.com</a>"</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> "<a href="mailto:sender@somewhere_else.com" target="_blank">sender@somewhere_else.com</a>"</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> "Haskell Email"</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> "I can finally send email from Haskell now!!"</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> conn</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> else print "Authentication failed."</b></font></div><div style="color:rgb(0,0,0);font-size:12.8px"><font face="monospace, monospace" size="1"><b> where settings = defaultSettingsSMTPSTARTTLS { sslPort = 587, sslLogToConsole = True }</b></font></div></div><div><font face="monospace, monospace" size="1"><b><br></b></font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 19, 2016 at 1:13 AM, David Escobar <span dir="ltr"><<a href="mailto:davidescobar1976@gmail.com" target="_blank">davidescobar1976@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Actually Daniel, I'm glad you mentioned it. <i>HaskellNet</i> and <i>HaskellNet-SSL</i> actually worked for me! Thank you for that!<div><br></div><div>The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting:</div><div><h5 style="border:0px;margin:0px;padding:0px;font-size:16px;font-weight:normal;color:rgb(24,24,24);font-family:Roboto,RobotoDraft,'Helvetica Neue',arial,sans-serif">Allow less secure apps: OFF</h5></div><div><br></div><div><font color="#000000">Doesn't seem ideal, but I'm not sure if that's a fault of the library itself or just the way it is with generic 3rd party apps that aren't somehow registered with Google. But in any case, when I try it with another Amazon AWS account, it doesn't have that problem, so it's all good since that's the real account I wanted to get it working with anyway (Gmail was just a more convenient "testing" platform).</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">In any case, here is the short generic code that works for future reference so that hopefully others don't have to go through the same process just to send an email. Thanks again Daniel, and thanks to everyone else for their answers as well!</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">P.S. the <b>sslLogToConsole</b> option is great for seeing the handshaking going on with the SMTP server.</font></div><div><font color="#000000"><br></font></div><div><font color="#000000"><div><font face="monospace, monospace" size="1"><b>main :: IO ()</b></font></div><div><font face="monospace, monospace" size="1"><b>main = doSMTPSTARTTLSWithSettings "<a href="http://smtp.gmail.com" target="_blank">smtp.gmail.com</a>" settings $ \conn -> do</b></font></div><div><font face="monospace, monospace" size="1"><b> authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn</b></font></div><div><font face="monospace, monospace" size="1"><b> if authSucceed</b></font></div><div><font face="monospace, monospace" size="1"><b> then do</b></font></div><div><font face="monospace, monospace" size="1"><b> putStrLn "Sending email..."</b></font></div><div><font face="monospace, monospace" size="1"><b> sendPlainTextMail "<a href="mailto:recipient@somewhere.com" target="_blank">recipient@somewhere.com</a>"</b></font></div><div><font face="monospace, monospace" size="1"><b> "<a href="mailto:sender@somewhere_else.com" target="_blank">sender@somewhere_else.com</a>"</b></font></div><div><font face="monospace, monospace" size="1"><b> "Haskell Email"</b></font></div><div><font face="monospace, monospace" size="1"><b> "I can finally send email from Haskell now!!"</b></font></div><div><font face="monospace, monospace" size="1"><b> conn</b></font></div><div><font face="monospace, monospace" size="1"><b> else print "Authentication failed."</b></font></div><div><font face="monospace, monospace" size="1"><b> where settings = defaultSettingsSMTPSTARTTLS { sslPort = 587, sslLogToConsole = True }</b></font></div><div><br></div></font></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 18, 2016 at 10:59 PM, Daniel P. Wright <span dir="ltr"><<a href="mailto:dani@dpwright.com" target="_blank">dani@dpwright.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Not to throw another spanner in the works with Yet Another Package to try, but another option is HaskellNet[1] with HaskellNet-SSL[2] for your TLS connection. I originally wrote the HaskellNet-SSL wrapper but it's currently being maintained by Leza Morais Lutonda. It works with gmail. I haven't tried any of the other SMTP options and I mostly used it for IMAP, not SMTP, so I can't compare them directly or recommend one over the other -- just throwing it out there as another option!<div><br></div><div>[1]: <a href="http://hackage.haskell.org/package/HaskellNet" target="_blank">http://hackage.haskell.org/package/HaskellNet</a></div><div>[2]: <a href="http://hackage.haskell.org/package/HaskellNet-SSL" target="_blank">http://hackage.haskell.org/package/HaskellNet-SSL</a></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>2016-04-19 6:42 GMT+09:00 David Escobar <span dir="ltr"><<a href="mailto:davidescobar1976@gmail.com" target="_blank">davidescobar1976@gmail.com</a>></span>:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Hi everyone,<div>I'm trying to use the <i>Network.Mail.SMTP</i> library to send email:</div><div><br></div><div><div><font face="monospace, monospace" size="1" color="#351c75"><b>{-# LANGUAGE OverloadedStrings #-}</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b><br></b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b>module Main where</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b><br></b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b>import Control.Exception</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b><br></b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b>import qualified Data.Text as T</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b>import qualified Data.Text.Lazy as LT</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b>import Network.Mail.SMTP</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b><br></b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b>main :: IO ()</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b>main = do</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> sendEmail (“Person sender”, “<a href="mailto:sender@somewhere.com" target="_blank">sender@somewhere.com</a>”)</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> [(“Person recipient“, “<a href="mailto:recipient@somewhere.com" target="_blank">recipient@somewhere.com</a>”)]</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> "Test email"</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> "Some message goes here."</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b><br></b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b><br></b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b>sendEmail :: (T.Text, T.Text) -> [(T.Text, T.Text)] -> T.Text -> T.Text -> IO ()</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b>sendEmail (fromName, fromEmail) toAddresses subject' body' = do</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> let toNameAddrs = map (\(toName, toEmail) -> Address (Just toName) toEmail) toAddresses</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> msg = simpleMail (Address (Just fromName) fromEmail)</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> toNameAddrs</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> []</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> []</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> subject'</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> [ plainTextPart $ LT.fromStrict body' ]</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> result <- try $ sendMailWithLogin' "<a href="http://smtp.gmail.com" target="_blank">smtp.gmail.com</a>"</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> 465 -- SSL port</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> “sender_login”</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> “sender_password”</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> msg :: IO (Either SomeException ())</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> case result of</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> Left e -> putStrLn $ "Exception caught: " ++ (displayException e)</b></font></div><div><font face="monospace, monospace" size="1" color="#351c75"><b> Right _ -> putStrLn "Sent email successfully."</b></font></div></div><div><font face="monospace, monospace" size="1" color="#351c75"><b><br></b></font></div><div><br></div><div>The program compiles, but when I run it, I get:</div><div>
<p><span><font face="monospace, monospace"><b>Exception caught: <socket: 49>: Data.ByteString.hGetLine: end of file</b></font></span></p><p><span>I tried using the TLS port of 587, but then I just get an authentication failure. Am I using the wrong library or is it just the wrong configuration. Thanks.</span></p></div></div>
<br></div></div><span>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>