Hi everyone, I'm trying to use the *Network.Mail.SMTP* library to send email: *{-# LANGUAGE OverloadedStrings #-}* *module Main where* *import Control.Exception* *import qualified Data.Text as T* *import qualified Data.Text.Lazy as LT* *import Network.Mail.SMTP* *main :: IO ()* *main = do* * sendEmail (“Person sender”, “sender@somewhere.com <sender@somewhere.com>”)* * [(“Person recipient“, “recipient@somewhere.com <recipient@somewhere.com>”)]* * "Test email"* * "Some message goes here."* *sendEmail :: (T.Text, T.Text) -> [(T.Text, T.Text)] -> T.Text -> T.Text -> IO ()* *sendEmail (fromName, fromEmail) toAddresses subject' body' = do* * let toNameAddrs = map (\(toName, toEmail) -> Address (Just toName) toEmail) toAddresses* * msg = simpleMail (Address (Just fromName) fromEmail)* * toNameAddrs* * []* * []* * subject'* * [ plainTextPart $ LT.fromStrict body' ]* * result <- try $ sendMailWithLogin' "smtp.gmail.com <http://smtp.gmail.com>"* * 465 -- SSL port* * “sender_login”* * “sender_password”* * msg :: IO (Either SomeException ())* * case result of* * Left e -> putStrLn $ "Exception caught: " ++ (displayException e)* * Right _ -> putStrLn "Sent email successfully."* The program compiles, but when I run it, I get: *Exception caught: <socket: 49>: Data.ByteString.hGetLine: end of file* 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.
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! [1]: http://hackage.haskell.org/package/HaskellNet [2]: http://hackage.haskell.org/package/HaskellNet-SSL 2016-04-19 6:42 GMT+09:00 David Escobar <davidescobar1976@gmail.com>:
Hi everyone, I'm trying to use the *Network.Mail.SMTP* library to send email:
*{-# LANGUAGE OverloadedStrings #-}*
*module Main where*
*import Control.Exception*
*import qualified Data.Text as T* *import qualified Data.Text.Lazy as LT* *import Network.Mail.SMTP*
*main :: IO ()* *main = do* * sendEmail (“Person sender”, “sender@somewhere.com <sender@somewhere.com>”)* * [(“Person recipient“, “recipient@somewhere.com <recipient@somewhere.com>”)]* * "Test email"* * "Some message goes here."*
*sendEmail :: (T.Text, T.Text) -> [(T.Text, T.Text)] -> T.Text -> T.Text -> IO ()* *sendEmail (fromName, fromEmail) toAddresses subject' body' = do* * let toNameAddrs = map (\(toName, toEmail) -> Address (Just toName) toEmail) toAddresses* * msg = simpleMail (Address (Just fromName) fromEmail)* * toNameAddrs* * []* * []* * subject'* * [ plainTextPart $ LT.fromStrict body' ]* * result <- try $ sendMailWithLogin' "smtp.gmail.com <http://smtp.gmail.com>"* * 465 -- SSL port* * “sender_login”* * “sender_password”* * msg :: IO (Either SomeException ())* * case result of* * Left e -> putStrLn $ "Exception caught: " ++ (displayException e)* * Right _ -> putStrLn "Sent email successfully."*
The program compiles, but when I run it, I get:
*Exception caught: <socket: 49>: Data.ByteString.hGetLine: end of file*
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.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Actually Daniel, I'm glad you mentioned it. *HaskellNet* and *HaskellNet-SSL* actually worked for me! Thank you for that! The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF 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). 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! P.S. the *sslLogToConsole* option is great for seeing the handshaking going on with the SMTP server. *main :: IO ()* *main = doSMTPSTARTTLSWithSettings "smtp.gmail.com <http://smtp.gmail.com>" settings $ \conn -> do* * authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn* * if authSucceed* * then do* * putStrLn "Sending email..."* * sendPlainTextMail "recipient@somewhere.com <recipient@somewhere.com>"* * "sender@somewhere_else.com <sender@somewhere_else.com>"* * "Haskell Email"* * "I can finally send email from Haskell now!!"* * conn* * else print "Authentication failed."* * where settings = defaultSettingsSMTPSTARTTLS { sslPort = 587, sslLogToConsole = True }* On Mon, Apr 18, 2016 at 10:59 PM, Daniel P. Wright <dani@dpwright.com> wrote:
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!
[1]: http://hackage.haskell.org/package/HaskellNet [2]: http://hackage.haskell.org/package/HaskellNet-SSL
2016-04-19 6:42 GMT+09:00 David Escobar <davidescobar1976@gmail.com>:
Hi everyone, I'm trying to use the *Network.Mail.SMTP* library to send email:
*{-# LANGUAGE OverloadedStrings #-}*
*module Main where*
*import Control.Exception*
*import qualified Data.Text as T* *import qualified Data.Text.Lazy as LT* *import Network.Mail.SMTP*
*main :: IO ()* *main = do* * sendEmail (“Person sender”, “sender@somewhere.com <sender@somewhere.com>”)* * [(“Person recipient“, “recipient@somewhere.com <recipient@somewhere.com>”)]* * "Test email"* * "Some message goes here."*
*sendEmail :: (T.Text, T.Text) -> [(T.Text, T.Text)] -> T.Text -> T.Text -> IO ()* *sendEmail (fromName, fromEmail) toAddresses subject' body' = do* * let toNameAddrs = map (\(toName, toEmail) -> Address (Just toName) toEmail) toAddresses* * msg = simpleMail (Address (Just fromName) fromEmail)* * toNameAddrs* * []* * []* * subject'* * [ plainTextPart $ LT.fromStrict body' ]* * result <- try $ sendMailWithLogin' "smtp.gmail.com <http://smtp.gmail.com>"* * 465 -- SSL port* * “sender_login”* * “sender_password”* * msg :: IO (Either SomeException ())* * case result of* * Left e -> putStrLn $ "Exception caught: " ++ (displayException e)* * Right _ -> putStrLn "Sent email successfully."*
The program compiles, but when I run it, I get:
*Exception caught: <socket: 49>: Data.ByteString.hGetLine: end of file*
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.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Forgot to include the header and imported modules in my last message: *{-# LANGUAGE OverloadedStrings #-}* *module Main where* *import Network.HaskellNet.SMTP* *import Network.HaskellNet.SMTP.SSL* *main :: IO ()* *main = doSMTPSTARTTLSWithSettings "smtp.gmail.com <http://smtp.gmail.com/>" settings $ \conn -> do* * authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn* * if authSucceed* * then do* * putStrLn "Sending email..."* * sendPlainTextMail "recipient@somewhere.com <recipient@somewhere.com>"* * "sender@somewhere_else.com <sender@somewhere_else.com>"* * "Haskell Email"* * "I can finally send email from Haskell now!!"* * conn* * else print "Authentication failed."* * where settings = defaultSettingsSMTPSTARTTLS { sslPort = 587, sslLogToConsole = True }* On Tue, Apr 19, 2016 at 1:13 AM, David Escobar <davidescobar1976@gmail.com> wrote:
Actually Daniel, I'm glad you mentioned it. *HaskellNet* and *HaskellNet-SSL* actually worked for me! Thank you for that!
The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF
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).
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!
P.S. the *sslLogToConsole* option is great for seeing the handshaking going on with the SMTP server.
*main :: IO ()* *main = doSMTPSTARTTLSWithSettings "smtp.gmail.com <http://smtp.gmail.com>" settings $ \conn -> do* * authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn* * if authSucceed* * then do* * putStrLn "Sending email..."* * sendPlainTextMail "recipient@somewhere.com <recipient@somewhere.com>"* * "sender@somewhere_else.com <sender@somewhere_else.com>"* * "Haskell Email"* * "I can finally send email from Haskell now!!"* * conn* * else print "Authentication failed."* * where settings = defaultSettingsSMTPSTARTTLS { sslPort = 587, sslLogToConsole = True }*
On Mon, Apr 18, 2016 at 10:59 PM, Daniel P. Wright <dani@dpwright.com> wrote:
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!
[1]: http://hackage.haskell.org/package/HaskellNet [2]: http://hackage.haskell.org/package/HaskellNet-SSL
2016-04-19 6:42 GMT+09:00 David Escobar <davidescobar1976@gmail.com>:
Hi everyone, I'm trying to use the *Network.Mail.SMTP* library to send email:
*{-# LANGUAGE OverloadedStrings #-}*
*module Main where*
*import Control.Exception*
*import qualified Data.Text as T* *import qualified Data.Text.Lazy as LT* *import Network.Mail.SMTP*
*main :: IO ()* *main = do* * sendEmail (“Person sender”, “sender@somewhere.com <sender@somewhere.com>”)* * [(“Person recipient“, “recipient@somewhere.com <recipient@somewhere.com>”)]* * "Test email"* * "Some message goes here."*
*sendEmail :: (T.Text, T.Text) -> [(T.Text, T.Text)] -> T.Text -> T.Text -> IO ()* *sendEmail (fromName, fromEmail) toAddresses subject' body' = do* * let toNameAddrs = map (\(toName, toEmail) -> Address (Just toName) toEmail) toAddresses* * msg = simpleMail (Address (Just fromName) fromEmail)* * toNameAddrs* * []* * []* * subject'* * [ plainTextPart $ LT.fromStrict body' ]* * result <- try $ sendMailWithLogin' "smtp.gmail.com <http://smtp.gmail.com>"* * 465 -- SSL port* * “sender_login”* * “sender_password”* * msg :: IO (Either SomeException ())* * case result of* * Left e -> putStrLn $ "Exception caught: " ++ (displayException e)* * Right _ -> putStrLn "Sent email successfully."*
The program compiles, but when I run it, I get:
*Exception caught: <socket: 49>: Data.ByteString.hGetLine: end of file*
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.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Hello David,
The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF
That does sound unusual! Is my understanding you correctly that HaskellNet doesn't work UNLESS you disallow less secure apps? Or is it the other (more intuitive) way round? (i.e. HaskellNet is being considered a "less secure" app and thus being disallowed). If it's the former it's not a massive priority even if it isn't ideal. If it's the latter it should probably be fixed. I'll try and look at it when I get the chance -- feel free to file an issue on HaskellNet-SSL in github. By the way, where is that setting in gmail? I had a look through the settings but couldn't see it. This might be because I'm using the Google Apps version of Gmail, not the public "@gmail.com" one. -Dani. 2016-04-19 17:13 GMT+09:00 David Escobar <davidescobar1976@gmail.com>:
Actually Daniel, I'm glad you mentioned it. *HaskellNet* and *HaskellNet-SSL* actually worked for me! Thank you for that!
The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF
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).
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!
P.S. the *sslLogToConsole* option is great for seeing the handshaking going on with the SMTP server.
*main :: IO ()* *main = doSMTPSTARTTLSWithSettings "smtp.gmail.com <http://smtp.gmail.com>" settings $ \conn -> do* * authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn* * if authSucceed* * then do* * putStrLn "Sending email..."* * sendPlainTextMail "recipient@somewhere.com <recipient@somewhere.com>"* * "sender@somewhere_else.com <sender@somewhere_else.com>"* * "Haskell Email"* * "I can finally send email from Haskell now!!"* * conn* * else print "Authentication failed."* * where settings = defaultSettingsSMTPSTARTTLS { sslPort = 587, sslLogToConsole = True }*
On Mon, Apr 18, 2016 at 10:59 PM, Daniel P. Wright <dani@dpwright.com> wrote:
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!
[1]: http://hackage.haskell.org/package/HaskellNet [2]: http://hackage.haskell.org/package/HaskellNet-SSL
2016-04-19 6:42 GMT+09:00 David Escobar <davidescobar1976@gmail.com>:
Hi everyone, I'm trying to use the *Network.Mail.SMTP* library to send email:
*{-# LANGUAGE OverloadedStrings #-}*
*module Main where*
*import Control.Exception*
*import qualified Data.Text as T* *import qualified Data.Text.Lazy as LT* *import Network.Mail.SMTP*
*main :: IO ()* *main = do* * sendEmail (“Person sender”, “sender@somewhere.com <sender@somewhere.com>”)* * [(“Person recipient“, “recipient@somewhere.com <recipient@somewhere.com>”)]* * "Test email"* * "Some message goes here."*
*sendEmail :: (T.Text, T.Text) -> [(T.Text, T.Text)] -> T.Text -> T.Text -> IO ()* *sendEmail (fromName, fromEmail) toAddresses subject' body' = do* * let toNameAddrs = map (\(toName, toEmail) -> Address (Just toName) toEmail) toAddresses* * msg = simpleMail (Address (Just fromName) fromEmail)* * toNameAddrs* * []* * []* * subject'* * [ plainTextPart $ LT.fromStrict body' ]* * result <- try $ sendMailWithLogin' "smtp.gmail.com <http://smtp.gmail.com>"* * 465 -- SSL port* * “sender_login”* * “sender_password”* * msg :: IO (Either SomeException ())* * case result of* * Left e -> putStrLn $ "Exception caught: " ++ (displayException e)* * Right _ -> putStrLn "Sent email successfully."*
The program compiles, but when I run it, I get:
*Exception caught: <socket: 49>: Data.ByteString.hGetLine: end of file*
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.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
On 04/20/2016 08:32 AM, Daniel P. Wright wrote:
Hello David,
The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF
That does sound unusual! Is my understanding you correctly that HaskellNet doesn't work UNLESS you disallow less secure apps? Or is it the other (more intuitive) way round? (i.e. HaskellNet is being considered a "less secure" app and thus being disallowed).
It's not particularly sinister... It's is simply that IMAP/SMTP do not have authentication options that are "secure enough" for Google[1]. Or perhaps rather that they at least must allow less secure authentication options per their respective standards/RFCs. Regards, [1] Basically they don't enforce two-factor auth.
Bardur, Ah, ok, that makes sense. Thanks for the clarification. -Dani. 2016-04-20 15:56 GMT+09:00 Bardur Arantsson <spam@scientician.net>:
On 04/20/2016 08:32 AM, Daniel P. Wright wrote:
Hello David,
The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF
That does sound unusual! Is my understanding you correctly that HaskellNet doesn't work UNLESS you disallow less secure apps? Or is it the other (more intuitive) way round? (i.e. HaskellNet is being considered a "less secure" app and thus being disallowed).
It's not particularly sinister...
It's is simply that IMAP/SMTP do not have authentication options that are "secure enough" for Google[1]. Or perhaps rather that they at least must allow less secure authentication options per their respective standards/RFCs.
Regards,
[1] Basically they don't enforce two-factor auth.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Hi Daniel, I have another issue when using HaskellNet. It seems the way the library sends email is causing extra spaces and line breaks to be inserted in my HTML emails, which completely messes up the inline CSS styles. When I turned *sslLogToConsole = True*, this is the kind of output I get in the log: *HaskellNet-SSL SEND: "<!DOCTYPE html>\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "<html><body><table style=3D\"border: 1px solid black; border-collapse: colla=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "pse; margin: 25px 0; width: 100%;\"><tr><th style=3D\"background-color: #072a=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "2d; color: white; font-weight: bold; border-right: 1px solid white; padding=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: ": 5px 10px; width: 33%;\">Committer</th>\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "<th style=3D\"background-color: #072a2d; color: white; font-weight: bold; bo=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "rder-right: 1px solid white; padding: 5px 10px; width: 33%;\">SHA1</th>\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "<th style=3D\"background-color: #072a2d; color: white; font-weight: bold; bo=\r"* *HaskellNet-SSL SEND: "\r\n"* As you can see, extra line breaks are being inserted right in the middle of the HTML/CSS, which completely messes it up. Is there a way to prevent that? The only option I could find was *Settings* *sslMaxLineLength*, but setting that to a high number doesn't solve the problem. Thanks, David On Wed, Apr 20, 2016 at 12:00 AM, Daniel P. Wright <dani@dpwright.com> wrote:
Bardur,
Ah, ok, that makes sense. Thanks for the clarification.
-Dani.
2016-04-20 15:56 GMT+09:00 Bardur Arantsson <spam@scientician.net>:
On 04/20/2016 08:32 AM, Daniel P. Wright wrote:
Hello David,
The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF
That does sound unusual! Is my understanding you correctly that HaskellNet doesn't work UNLESS you disallow less secure apps? Or is it the other (more intuitive) way round? (i.e. HaskellNet is being considered a "less secure" app and thus being disallowed).
It's not particularly sinister...
It's is simply that IMAP/SMTP do not have authentication options that are "secure enough" for Google[1]. Or perhaps rather that they at least must allow less secure authentication options per their respective standards/RFCs.
Regards,
[1] Basically they don't enforce two-factor auth.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Hi David, Off the top of my head I'm not sure what the root cause of that would be, or indeed if the problem lies with HaskellNet-SSL or with HaskellNet itself. If you can send me some sample code (either by email or by filing an issue at https://github.com/dpwright/HaskellNet-SSL/issues) I can take a look at it. -Dani. 2016-04-27 16:14 GMT+09:00 David Escobar <davidescobar@ieee.org>:
Hi Daniel, I have another issue when using HaskellNet. It seems the way the library sends email is causing extra spaces and line breaks to be inserted in my HTML emails, which completely messes up the inline CSS styles. When I turned *sslLogToConsole = True*, this is the kind of output I get in the log:
*HaskellNet-SSL SEND: "<!DOCTYPE html>\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "<html><body><table style=3D\"border: 1px solid black; border-collapse: colla=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "pse; margin: 25px 0; width: 100%;\"><tr><th style=3D\"background-color: #072a=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "2d; color: white; font-weight: bold; border-right: 1px solid white; padding=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: ": 5px 10px; width: 33%;\">Committer</th>\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "<th style=3D\"background-color: #072a2d; color: white; font-weight: bold; bo=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "rder-right: 1px solid white; padding: 5px 10px; width: 33%;\">SHA1</th>\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "<th style=3D\"background-color: #072a2d; color: white; font-weight: bold; bo=\r"* *HaskellNet-SSL SEND: "\r\n"*
As you can see, extra line breaks are being inserted right in the middle of the HTML/CSS, which completely messes it up. Is there a way to prevent that? The only option I could find was *Settings* *sslMaxLineLength*, but setting that to a high number doesn't solve the problem.
Thanks, David
On Wed, Apr 20, 2016 at 12:00 AM, Daniel P. Wright <dani@dpwright.com> wrote:
Bardur,
Ah, ok, that makes sense. Thanks for the clarification.
-Dani.
2016-04-20 15:56 GMT+09:00 Bardur Arantsson <spam@scientician.net>:
On 04/20/2016 08:32 AM, Daniel P. Wright wrote:
Hello David,
The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF
That does sound unusual! Is my understanding you correctly that HaskellNet doesn't work UNLESS you disallow less secure apps? Or is it the other (more intuitive) way round? (i.e. HaskellNet is being considered a "less secure" app and thus being disallowed).
It's not particularly sinister...
It's is simply that IMAP/SMTP do not have authentication options that are "secure enough" for Google[1]. Or perhaps rather that they at least must allow less secure authentication options per their respective standards/RFCs.
Regards,
[1] Basically they don't enforce two-factor auth.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
I think I found what the problem was. I was using an Amazon SES account and even though the email got sent successfully, the HTML and CSS got messed up. When I used a regular Gmail account, the email came through with the HTML and CSS as intended. So it must be something different in the way SES expects this to be sent (what threw me off was that the email still got sent). I guess that's the reason the *Network.Mail.Mime.SES* package exists, so I'll switch over to using that one for the SES account and try and get that working. Thanks. On Wed, Apr 27, 2016 at 1:32 AM, Daniel P. Wright <dani@dpwright.com> wrote:
Hi David,
Off the top of my head I'm not sure what the root cause of that would be, or indeed if the problem lies with HaskellNet-SSL or with HaskellNet itself. If you can send me some sample code (either by email or by filing an issue at https://github.com/dpwright/HaskellNet-SSL/issues) I can take a look at it.
-Dani.
2016-04-27 16:14 GMT+09:00 David Escobar <davidescobar@ieee.org>:
Hi Daniel, I have another issue when using HaskellNet. It seems the way the library sends email is causing extra spaces and line breaks to be inserted in my HTML emails, which completely messes up the inline CSS styles. When I turned *sslLogToConsole = True*, this is the kind of output I get in the log:
*HaskellNet-SSL SEND: "<!DOCTYPE html>\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "<html><body><table style=3D\"border: 1px solid black; border-collapse: colla=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "pse; margin: 25px 0; width: 100%;\"><tr><th style=3D\"background-color: #072a=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "2d; color: white; font-weight: bold; border-right: 1px solid white; padding=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: ": 5px 10px; width: 33%;\">Committer</th>\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "<th style=3D\"background-color: #072a2d; color: white; font-weight: bold; bo=\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "rder-right: 1px solid white; padding: 5px 10px; width: 33%;\">SHA1</th>\r"* *HaskellNet-SSL SEND: "\r\n"* *HaskellNet-SSL SEND: "<th style=3D\"background-color: #072a2d; color: white; font-weight: bold; bo=\r"* *HaskellNet-SSL SEND: "\r\n"*
As you can see, extra line breaks are being inserted right in the middle of the HTML/CSS, which completely messes it up. Is there a way to prevent that? The only option I could find was *Settings* *sslMaxLineLength*, but setting that to a high number doesn't solve the problem.
Thanks, David
On Wed, Apr 20, 2016 at 12:00 AM, Daniel P. Wright <dani@dpwright.com> wrote:
Bardur,
Ah, ok, that makes sense. Thanks for the clarification.
-Dani.
2016-04-20 15:56 GMT+09:00 Bardur Arantsson <spam@scientician.net>:
On 04/20/2016 08:32 AM, Daniel P. Wright wrote:
Hello David,
The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF
That does sound unusual! Is my understanding you correctly that HaskellNet doesn't work UNLESS you disallow less secure apps? Or is it the other (more intuitive) way round? (i.e. HaskellNet is being considered a "less secure" app and thus being disallowed).
It's not particularly sinister...
It's is simply that IMAP/SMTP do not have authentication options that are "secure enough" for Google[1]. Or perhaps rather that they at least must allow less secure authentication options per their respective standards/RFCs.
Regards,
[1] Basically they don't enforce two-factor auth.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Yes, I meant that it only worked by turning less secure apps ON. Sorry for the confusion. From Bardur's comment, it sounds like it's all good. The setting for this is actually outside of Gmail, under *myaccount.google.com <http://myaccount.google.com>* and then you go to "Connected apps & sites". Thanks again. David On Tue, Apr 19, 2016 at 11:32 PM, Daniel P. Wright <dani@dpwright.com> wrote:
Hello David,
The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF
That does sound unusual! Is my understanding you correctly that HaskellNet doesn't work UNLESS you disallow less secure apps? Or is it the other (more intuitive) way round? (i.e. HaskellNet is being considered a "less secure" app and thus being disallowed).
If it's the former it's not a massive priority even if it isn't ideal. If it's the latter it should probably be fixed. I'll try and look at it when I get the chance -- feel free to file an issue on HaskellNet-SSL in github.
By the way, where is that setting in gmail? I had a look through the settings but couldn't see it. This might be because I'm using the Google Apps version of Gmail, not the public "@gmail.com" one.
-Dani.
2016-04-19 17:13 GMT+09:00 David Escobar <davidescobar1976@gmail.com>:
Actually Daniel, I'm glad you mentioned it. *HaskellNet* and *HaskellNet-SSL* actually worked for me! Thank you for that!
The only thing I noticed with Gmail is that in order to work it requires the sender's account to toggle this setting: Allow less secure apps: OFF
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).
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!
P.S. the *sslLogToConsole* option is great for seeing the handshaking going on with the SMTP server.
*main :: IO ()* *main = doSMTPSTARTTLSWithSettings "smtp.gmail.com <http://smtp.gmail.com>" settings $ \conn -> do* * authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn* * if authSucceed* * then do* * putStrLn "Sending email..."* * sendPlainTextMail "recipient@somewhere.com <recipient@somewhere.com>"* * "sender@somewhere_else.com <sender@somewhere_else.com>"* * "Haskell Email"* * "I can finally send email from Haskell now!!"* * conn* * else print "Authentication failed."* * where settings = defaultSettingsSMTPSTARTTLS { sslPort = 587, sslLogToConsole = True }*
On Mon, Apr 18, 2016 at 10:59 PM, Daniel P. Wright <dani@dpwright.com> wrote:
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!
[1]: http://hackage.haskell.org/package/HaskellNet [2]: http://hackage.haskell.org/package/HaskellNet-SSL
2016-04-19 6:42 GMT+09:00 David Escobar <davidescobar1976@gmail.com>:
Hi everyone, I'm trying to use the *Network.Mail.SMTP* library to send email:
*{-# LANGUAGE OverloadedStrings #-}*
*module Main where*
*import Control.Exception*
*import qualified Data.Text as T* *import qualified Data.Text.Lazy as LT* *import Network.Mail.SMTP*
*main :: IO ()* *main = do* * sendEmail (“Person sender”, “sender@somewhere.com <sender@somewhere.com>”)* * [(“Person recipient“, “recipient@somewhere.com <recipient@somewhere.com>”)]* * "Test email"* * "Some message goes here."*
*sendEmail :: (T.Text, T.Text) -> [(T.Text, T.Text)] -> T.Text -> T.Text -> IO ()* *sendEmail (fromName, fromEmail) toAddresses subject' body' = do* * let toNameAddrs = map (\(toName, toEmail) -> Address (Just toName) toEmail) toAddresses* * msg = simpleMail (Address (Just fromName) fromEmail)* * toNameAddrs* * []* * []* * subject'* * [ plainTextPart $ LT.fromStrict body' ]* * result <- try $ sendMailWithLogin' "smtp.gmail.com <http://smtp.gmail.com>"* * 465 -- SSL port* * “sender_login”* * “sender_password”* * msg :: IO (Either SomeException ())* * case result of* * Left e -> putStrLn $ "Exception caught: " ++ (displayException e)* * Right _ -> putStrLn "Sent email successfully."*
The program compiles, but when I run it, I get:
*Exception caught: <socket: 49>: Data.ByteString.hGetLine: end of file*
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.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
participants (4)
-
Bardur Arantsson -
Daniel P. Wright -
David Escobar -
David Escobar