Sending email

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|

Sending email

David Escobar
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”, “[hidden email]”)
            [(“Person recipient“, “[hidden email]”)]
            "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"
                                     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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

David Escobar
No explicit mention is made anywhere in the documentation about TLS or even SSL, so perhaps not? Some libraries I've come across specifically mention that they don't support TLS or SSL. Being relatively new to this part of Haskell, what is the most standard library the community uses for email that supports modern protocols such as those used by GMail? Thanks.

On Mon, Apr 18, 2016 at 2:49 PM, Alex Feldman-Crough <[hidden email]> wrote:
Does the library support TLS? Does it have to be configured differently? It sounds like a negotiation error to me.
On Mon, Apr 18, 2016 at 2:43 PM David Escobar <[hidden email]> wrote:
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”, “[hidden email]”)
            [(“Person recipient“, “[hidden email]”)]
            "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"
                                     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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
--
Alex Feldman Crough
<a href="tel:602%20573-9588" value="+16025739588" target="_blank">602 573-9588


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

Alexander Vieth-2
Right, you need to STARTTLS and upgrade to a secure connection before trying to authenticate, but smtp-mail will not take care of this for you. You could do it manually, using the tls package, or you could try smtp-mail-ng[1][2].

Alex

[1] https://github.com/avieth/smtp-mail-ng
[2] https://hackage.haskell.org/package/smtp-mail-ng-0.1.0.1

On Mon, Apr 18, 2016 at 6:36 PM, David Escobar <[hidden email]> wrote:
No explicit mention is made anywhere in the documentation about TLS or even SSL, so perhaps not? Some libraries I've come across specifically mention that they don't support TLS or SSL. Being relatively new to this part of Haskell, what is the most standard library the community uses for email that supports modern protocols such as those used by GMail? Thanks.

On Mon, Apr 18, 2016 at 2:49 PM, Alex Feldman-Crough <[hidden email]> wrote:
Does the library support TLS? Does it have to be configured differently? It sounds like a negotiation error to me.
On Mon, Apr 18, 2016 at 2:43 PM David Escobar <[hidden email]> wrote:
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”, “[hidden email]”)
            [(“Person recipient“, “[hidden email]”)]
            "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"
                                     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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
--
Alex Feldman Crough
<a href="tel:602%20573-9588" value="+16025739588" target="_blank">602 573-9588


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

Donn Cave-4
In reply to this post by David Escobar
quoth David Escobar <[hidden email]>

> No explicit mention is made anywhere in the documentation about TLS or even
> SSL, so perhaps not? Some libraries I've come across specifically mention
> that they don't support TLS or SSL. Being relatively new to this part of
> Haskell, what is the most standard library the community uses for email
> that supports modern protocols such as those used by GMail? Thanks.

I'm not going to guess what the community is up to, but it seems
to me like the least novel way to get there would be an SSL connection
to port 465, using HsOpenSSL, and use the library you were already using
for SMTP.

I do that, essentially, though with home rolled stuff for various
not very interesting reasons.  So I haven't tried these two packages,
but I can assure you that the principle works with gmail.

If your SMTP package won't accept some kind of generic I/O channel
and insists on making and using its own socket connection, then
you'll need something else.  Ideally, it would provide pure functions
for SMTP parsing and protocol interpretation, and you could do the
I/O stuff yourself via whatever channel you wish, but that pure/io
structural division seems surprisingly rare among Haskell network
application packages.

        Donn
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

David Escobar
In reply to this post by Alexander Vieth-2
Thanks Alex. I'll start looking into that.


On Mon, Apr 18, 2016 at 3:43 PM, Alexander Vieth <[hidden email]> wrote:
Right, you need to STARTTLS and upgrade to a secure connection before trying to authenticate, but smtp-mail will not take care of this for you. You could do it manually, using the tls package, or you could try smtp-mail-ng[1][2].

Alex

[1] https://github.com/avieth/smtp-mail-ng
[2] https://hackage.haskell.org/package/smtp-mail-ng-0.1.0.1

On Mon, Apr 18, 2016 at 6:36 PM, David Escobar <[hidden email]> wrote:
No explicit mention is made anywhere in the documentation about TLS or even SSL, so perhaps not? Some libraries I've come across specifically mention that they don't support TLS or SSL. Being relatively new to this part of Haskell, what is the most standard library the community uses for email that supports modern protocols such as those used by GMail? Thanks.

On Mon, Apr 18, 2016 at 2:49 PM, Alex Feldman-Crough <[hidden email]> wrote:
Does the library support TLS? Does it have to be configured differently? It sounds like a negotiation error to me.
On Mon, Apr 18, 2016 at 2:43 PM David Escobar <[hidden email]> wrote:
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”, “[hidden email]”)
            [(“Person recipient“, “[hidden email]”)]
            "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"
                                     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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
--
Alex Feldman Crough
<a href="tel:602%20573-9588" value="+16025739588" target="_blank">602 573-9588


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe




_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

David Escobar-2
In reply to this post by Donn Cave-4
Thanks, that makes sense. Out of curiosity, which one do you use with HsOpenSSL?


On Mon, Apr 18, 2016 at 4:23 PM, Donn Cave <[hidden email]> wrote:
quoth David Escobar <[hidden email]>

> No explicit mention is made anywhere in the documentation about TLS or even
> SSL, so perhaps not? Some libraries I've come across specifically mention
> that they don't support TLS or SSL. Being relatively new to this part of
> Haskell, what is the most standard library the community uses for email
> that supports modern protocols such as those used by GMail? Thanks.

I'm not going to guess what the community is up to, but it seems
to me like the least novel way to get there would be an SSL connection
to port 465, using HsOpenSSL, and use the library you were already using
for SMTP.

I do that, essentially, though with home rolled stuff for various
not very interesting reasons.  So I haven't tried these two packages,
but I can assure you that the principle works with gmail.

If your SMTP package won't accept some kind of generic I/O channel
and insists on making and using its own socket connection, then
you'll need something else.  Ideally, it would provide pure functions
for SMTP parsing and protocol interpretation, and you could do the
I/O stuff yourself via whatever channel you wish, but that pure/io
structural division seems surprisingly rare among Haskell network
application packages.

        Donn
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

Donn Cave-4
quoth David Escobar <[hidden email]>
 
> Thanks, that makes sense. Out of curiosity, which one do you use with
> HsOpenSSL?

[... where I said ...]
>> I do that, essentially, though with home rolled stuff for various
>> not very interesting reasons.  So I haven't tried these two packages,

"Home rolled" means I wrote my own SMTP protocol software, and my own
OpenSSL wrapper.  I haven't tried HsOpenSSL and don't know anything about it -
want to be clear about that!

        Donn
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

David Escobar
In reply to this post by David Escobar
Alex, unfortunately I get compiler errors when adding the smtp-mail-ng library (I'm using Stack for my dependency management/builds). Not sure if I'm doing something wrong on my end, but it seems to be something in the library itself.

    /private/var/folders/kg/p_frph3n0d71yfmvn553s4rh0000gn/T/stack69375/smtp-mail-ng-0.1.0.2/Network/Mail/SMTP/SMTP.hs:201:3:
        Couldn't match type ‘Context’ with ‘IO Context’
        Expected type: SystemRNG -> IO Context
          Actual type: SystemRNG -> Context
        The function ‘contextNew’ is applied to three arguments,
        its type is ‘backend0 -> params0 -> m0 Context’,
        it is specialized to ‘Handle
                              -> ClientParams -> SystemRNG -> Context’
        In a stmt of a 'do' block: contextNew handle params rng
        In the expression:
          do { rng <- (createEntropyPool >>= return . cprgCreate) ::
                        IO SystemRNG;
               certStore <- getSystemCertificateStore;
               let params = tlsClientParams hostname certStore;
               contextNew handle params rng }


On Mon, Apr 18, 2016 at 6:15 PM, David Escobar <[hidden email]> wrote:
Thanks Alex. I'll start looking into that.


On Mon, Apr 18, 2016 at 3:43 PM, Alexander Vieth <[hidden email]> wrote:
Right, you need to STARTTLS and upgrade to a secure connection before trying to authenticate, but smtp-mail will not take care of this for you. You could do it manually, using the tls package, or you could try smtp-mail-ng[1][2].

Alex

[1] https://github.com/avieth/smtp-mail-ng
[2] https://hackage.haskell.org/package/smtp-mail-ng-0.1.0.1

On Mon, Apr 18, 2016 at 6:36 PM, David Escobar <[hidden email]> wrote:
No explicit mention is made anywhere in the documentation about TLS or even SSL, so perhaps not? Some libraries I've come across specifically mention that they don't support TLS or SSL. Being relatively new to this part of Haskell, what is the most standard library the community uses for email that supports modern protocols such as those used by GMail? Thanks.

On Mon, Apr 18, 2016 at 2:49 PM, Alex Feldman-Crough <[hidden email]> wrote:
Does the library support TLS? Does it have to be configured differently? It sounds like a negotiation error to me.
On Mon, Apr 18, 2016 at 2:43 PM David Escobar <[hidden email]> wrote:
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”, “[hidden email]”)
            [(“Person recipient“, “[hidden email]”)]
            "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"
                                     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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
--
Alex Feldman Crough
<a href="tel:602%20573-9588" value="+16025739588" target="_blank">602 573-9588


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe





_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

David Escobar-2
In reply to this post by Donn Cave-4
Oh ok, my misunderstanding. I didn't realized you had done all that!


On Mon, Apr 18, 2016 at 6:53 PM, Donn Cave <[hidden email]> wrote:
quoth David Escobar <[hidden email]>

> Thanks, that makes sense. Out of curiosity, which one do you use with
> HsOpenSSL?

[... where I said ...]
>> I do that, essentially, though with home rolled stuff for various
>> not very interesting reasons.  So I haven't tried these two packages,

"Home rolled" means I wrote my own SMTP protocol software, and my own
OpenSSL wrapper.  I haven't tried HsOpenSSL and don't know anything about it -
want to be clear about that!

        Donn
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

Daniel P. Wright
In reply to this post by David Escobar
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!


2016-04-19 6:42 GMT+09:00 David Escobar <[hidden email]>:
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”, “[hidden email]”)
            [(“Person recipient“, “[hidden email]”)]
            "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"
                                     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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

David Escobar
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" settings $ \conn -> do
  authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn
  if authSucceed
    then do
      putStrLn "Sending email..."
      sendPlainTextMail "[hidden email]"
                                    "[hidden email]"
                                    "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 <[hidden email]> 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!


2016-04-19 6:42 GMT+09:00 David Escobar <[hidden email]>:
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”, “[hidden email]”)
            [(“Person recipient“, “[hidden email]”)]
            "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"
                                     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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe




_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

David Escobar
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" settings $ \conn -> do
  authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn
  if authSucceed
    then do
      putStrLn "Sending email..."
      sendPlainTextMail "[hidden email]"
                        "[hidden email]"
                        "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 <[hidden email]> 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" settings $ \conn -> do
  authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn
  if authSucceed
    then do
      putStrLn "Sending email..."
      sendPlainTextMail "[hidden email]"
                                    "[hidden email]"
                                    "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 <[hidden email]> 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!


2016-04-19 6:42 GMT+09:00 David Escobar <[hidden email]>:
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”, “[hidden email]”)
            [(“Person recipient“, “[hidden email]”)]
            "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"
                                     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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe





_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

Daniel P. Wright
In reply to this post by David Escobar
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 <[hidden email]>:
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" settings $ \conn -> do
  authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn
  if authSucceed
    then do
      putStrLn "Sending email..."
      sendPlainTextMail "[hidden email]"
                                    "[hidden email]"
                                    "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 <[hidden email]> 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!


2016-04-19 6:42 GMT+09:00 David Escobar <[hidden email]>:
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”, “[hidden email]”)
            [(“Person recipient“, “[hidden email]”)]
            "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"
                                     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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe





_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

Bardur Arantsson-2
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

Daniel P. Wright
Bardur,

Ah, ok, that makes sense.  Thanks for the clarification.

-Dani.

2016-04-20 15:56 GMT+09:00 Bardur Arantsson <[hidden email]>:
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

David Escobar
In reply to this post by Daniel P. Wright
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 and then you go to "Connected apps & sites".

Thanks again.
David


On Tue, Apr 19, 2016 at 11:32 PM, Daniel P. Wright <[hidden email]> 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 <[hidden email]>:
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" settings $ \conn -> do
  authSucceed <- authenticate LOGIN "gmail_login" "gmail_password" conn
  if authSucceed
    then do
      putStrLn "Sending email..."
      sendPlainTextMail "[hidden email]"
                                    "[hidden email]"
                                    "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 <[hidden email]> 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!


2016-04-19 6:42 GMT+09:00 David Escobar <[hidden email]>:
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”, “[hidden email]”)
            [(“Person recipient“, “[hidden email]”)]
            "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"
                                     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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe






_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

David Escobar-2
In reply to this post by Daniel P. Wright
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 <[hidden email]> wrote:
Bardur,

Ah, ok, that makes sense.  Thanks for the clarification.

-Dani.

2016-04-20 15:56 GMT+09:00 Bardur Arantsson <[hidden email]>:
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

Daniel P. Wright
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 <[hidden email]>:
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 <[hidden email]> wrote:
Bardur,

Ah, ok, that makes sense.  Thanks for the clarification.

-Dani.

2016-04-20 15:56 GMT+09:00 Bardur Arantsson <[hidden email]>:
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe




_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Sending email

David Escobar-2
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 <[hidden email]> 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 <[hidden email]>:
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 <[hidden email]> wrote:
Bardur,

Ah, ok, that makes sense.  Thanks for the clarification.

-Dani.

2016-04-20 15:56 GMT+09:00 Bardur Arantsson <[hidden email]>:
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe





_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe