Do I need to hide the SMTP server? If so, how to do it?

I have been trying for a long time to send an email form as part of the Haskell program, tried to use the HaskellMime library or something like that, but failed.
I recently installed HaskellNet and tried using the Haskellnet.SMTP module. I tried to send an email with the command "sendMail" and get a "user error (SendMail error)." I suppose this is because the SMTP server I used requires authentication.
I took a look at the source code of sendMail and eventually wrote this simple main: http://hpaste.org/47841
I checked every sendCommand command and after the AUTH command I got "Auth success" from the SMTP server and 250 code from other commands, like and expected in the source code of sendMail.
The problem is that I don't have mail in my inbox, so what am I doing wrong? The only thing I can think of is that the mail is queued in the outgoing SMTP list and I need to clear the SMTP server, but this is not part of the sendMail code, so I wonder ... Any help would be greatly appreciated , because I never thought it would be so difficult to send an email: /
Postscript I use the same settings on my phone to send email with this SMTP server, the same "smtp.sfr.fr", with the same identifier (entire address) and the same password; and it works: I can send letters from my phone.
Thank you in advance.

+5
source share
1 answer

While I cannot comment on your use of HaskellNet, I have had great success using SMTPClient , which you can extract from a hack with cabal install SMTPClient.

I included a sample package to give you an idea of ​​how the library works:

import Network.SMTP.ClientSession
import Network.SMTP.Client
import Network.Socket
import System.Time
import System.IO
import Data.Bits
import Data.IORef

myDomain = "example.com"
smtpHost = "hubert.blacksapphire.com"    -- <-- Your SMTP server here

-- This will send the author an email.  I don't mind!
main = do
    now <- getClockTime
    nowCT <- toCalendarTime now
    let message = Message [
                From [NameAddr (Just "Mr. Nobody") "nobody@example.com"],
                To   [NameAddr (Just "Stephen Blackheath") "unprintable.distances.stephen@blacksapphire.com"],
                Subject "I'm using SMTPClient!",
                Date nowCT
            ]
            ("Dear Sir,\n"++
             "It has come to my attention that this is an email.\n"++
             "Yours sincerely,\n"++
             "Mr. Nobody\n")
    addrs <- getAddrInfo Nothing (Just smtpHost) Nothing
    let SockAddrInet _ hostAddr = addrAddress (addrs !! 0)
        sockAddr = SockAddrInet (fromIntegral 25) hostAddr
    putStrLn $ "connecting to "++show sockAddr
    sentRef <- newIORef []
    sendSMTP' (hPutStrLn stderr) (Just sentRef) myDomain
        sockAddr [message]
    statuses <- readIORef sentRef
    -- If no exception was caught, statuses is guaranteed to be
    -- the same length as the list of input messages, therefore head won't fail here.
    case head statuses of
        Nothing     -> putStrLn "Message successfully sent"
        Just status -> putStrLn $ "Message send failed with status "++show status
+2
source

All Articles