jhickner / smtp-mail

Making it easy to send SMTP email from Haskell
BSD 3-Clause "New" or "Revised" License
75 stars 32 forks source link

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

Open ivnsch opened 6 years ago

ivnsch commented 6 years ago

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?

nixorn commented 6 years ago

+1 to this issue. Problem somewhere in deep of https://github.com/jhickner/smtp-mail/blob/master/Network/Mail/SMTP.hs#L255

ColtHands commented 6 years ago

+1 here

ColtHands commented 6 years ago

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.

chshersh commented 5 years ago

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...