jhickner/smtp-mail

<socket: 6>: Data.ByteString.hGetLine: end of file

ivnsch opened this issue · 4 comments

I get this error when calling sendMailWithLogin' "smtp.gmail.com" 465 "myemail@gmail.com" "password" mail

Nothing else! How do I get more information about the error? Any idea what can be causing it?

+1 here

This problem also occured with packages like HaskellNet and mime-mail.

For me problem was that my smtp server had a SSL connection security and i don't think this package has a SSL solution.

Below is the working code:

{-# OPTIONS -fno-warn-missing-signatures #-}
{-# LANGUAGE OverloadedStrings #-}

module SendMail (mailer) where

import System.IO
import Network.Mail.Mime
import Network.HaskellNet.SMTP
import Network.HaskellNet.SMTP.SSL
import Network.HaskellNet.Auth
import qualified Data.Text as T
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as B

server       = "smtp.yandex.com"
port         = 465
authType     = LOGIN
from         = ""
to           = ""
subject      = "Network.HaskellNet.SMTP Test :)"
plainBody    = "Hello world!"
htmlBody     = "<html><head></head><body><h1>Hello <i>world!</i></h1></body></html>"
attachments  = [] -- example [("application/octet-stream", "/path/to/file1.tar.gz), ("application/pdf", "/path/to/file2.pdf")]

mailer = doSMTPSSL server $ \conn -> do
    putStrLn "usr: "
    username <- getLine
    putStrLn "pass: "
    password <-getLine
    print $ username
    print $ password
    authSuccess <- authenticate authType username password conn
    if authSuccess
        then
            sendMimeMail to from subject plainBody htmlBody [] conn
        else putStrLn "Authentication failed."

The key here is HaskellNet-SSL package wich provides SSL connection and mime-mail that constructs the mails themselves.

Is it possible to add SSL support to smpt-mail package? I discovered the following Reddit post and SSL support was requested 5 years ago:

Apparently, the person who wanted to send PR didn't manage to do this...