dpwright / HaskellNet-SSL

Helpers to connect to SSL/TLS mail servers with HaskellNet
BSD 3-Clause "New" or "Revised" License
21 stars 30 forks source link

smtp-example gives exception #2

Closed fegu closed 10 years ago

fegu commented 10 years ago

Unsure if this is an issue with HaskellNet or HaskellNet-SSL, but when I download the most recent versions from Github and try smtpTest in example.hs I get, on both Mac and Windows:

*\ Exception: <socket: 11>: hPutBuf: illegal operation (handle is closed)

If I try the same code on an Office365 account I get:

*\ Exception: HandshakeFailed Error_EOF

Please let me know if you need any more information. I would be happy to help out.

dpwright commented 10 years ago

Hmm, it works for me, although I had to fiddle with the version numbers of some of the dependent libraries to get it to build. I've pushed those changes, along with a tweak to examples/gmail.hs to set sslMaxLineLength. Could you try getting the latest and running it in a cabal sandbox?

If it still happens for you in a sandbox with the latest .cabal file we can probably rule out it being a problem with one of the dependencies...

fegu commented 10 years ago

I got the latest HaskellNet and HaskellNet-SSL, and I upgraded tls from 1.1.5 to 1.2.2, connection from 0.1.3.1 to 0.2.0 (although not in a sandbox) but same result. I upgraded network 2.4.1.2 to 2.4.2.2 as well, but was unable to use it as PortNumber insisted on coming from 2.4.1.2 causing a version mismatch.

The error messages changed after this. While gmail stays the same, Office365 now reports *\ Exception: user error (authentication failed.) on known good credentials. So definitely, something is up with the different versions here.

But I also tested with a third email provider pair.com, which works perfectly both before and after upgrade. I forgot to mention earlier that IMAP works perfectly with all three providers (gmail, office365, pair).

While testing I also found the default connection timeout to be extremely long (2 minutes?).

Edit: the reason i did not try sandbox is that my windows install is still on cabal 1.16 and fails on cabal install cabal-install (even when running as administrator).

dpwright commented 10 years ago

I tried running on Windows in case that was the issue (I've been testing on Linux until now), but gmail still connected. When I tried sending with mailgun, however, I got an authentication failure, which is when I realised that the smtpTest example doesn't actually check the response of the AUTH command and just tries to send the email regardless. I've updated the example to check the response and print it out on failure.

I am still not entirely sure why I was getting the authentication failure. I took a quick glance at the Network.HaskellNet.Auth.plain function and it looks reasonable to me, and connecting manually through openssl s_client -starttls smtp -crlf -connect smtp.mailgun.org:587 authenticates fine. At any rate, I think this is at the authentication level, not the SSL level, and so the problem likely lies closer to HaskellNet than HaskellNet-SSL.

I've updated the example to use AUTH LOGIN rather than AUTH PLAIN. Could you try with the latest and see if it still fails for both mailservers? That way we'll know if it is an authentication problem (even the one reporting differently), or if there are other problems as well.

Thanks!

fegu commented 10 years ago

Strangely enough, all of the providers now work fine!

Except that Office365 takes a very long time, almost 30 secs, on the initial sendCommand.

∷ Finn Espen Gundersen

From: Daniel P. Wright [mailto:notifications@github.com] Sent: 4. februar 2014 00:58 To: dpwright/HaskellNet-SSL Cc: Finn Espen Gundersen Subject: Re: [HaskellNet-SSL] smtp-example gives exception (#2)

I tried running on Windows in case that was the issue (I've been testing on Linux until now), but gmail still connected. When I tried sending with mailgun, however, I got an authentication failure, which is when I realised that the smtpTest example doesn't actually check the response of the AUTH command and just tries to send the email regardless. I've updated the example to check the response and print it out on failure.

I am still not entirely sure why I was getting the authentication failure. I took a quick glance at the Network.HaskellNet.Auth.plain function and it looks reasonable to me, and connecting manually through openssl s_client -starttls smtp -crlf -connect smtp.mailgun.org:587 authenticates fine. At any rate, I think this is at the authentication level, not the SSL level, and so the problem likely lies closer to HaskellNet than HaskellNet-SSL.

I've updated the example to use AUTH LOGIN rather than AUTH PLAIN, and to print out the response when authentication fails. Could you try with the latest and see if it still fails for both mailservers? That way we'll know if it is an authentication problem (even the one reporting differently), or if there are other problems as well.

Thanks!

— Reply to this email directly or https://github.com/dpwright/HaskellNet-SSL/issues/2#issuecomment-34015913 view it on GitHub. https://github.com/notifications/beacon/1837982__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcwNzAwNDY4OCwiZGF0YSI6eyJpZCI6MjQ1NDUyNTl9fQ==--bcaa748e333bf1c99958b9416d51b0c15485ea98.gif