[Haskell-beginners] Using tls-extra for simple smtp

Sarfraz K. dragoon.empire at yahoo.fr
Tue Jul 3 17:16:37 CEST 2012


I am trying to write a simple script to send a mail via my gmail account. 
But I am a beginner so it is not that simple. 
I tryed google but exept for hackage, there is no help or examples at all.

The problem is that I did not find the way to use tls-extra(or tls) 
to initiate the STARTTLS exchange.


Ok, here is the code:

    import Network
    import Network.TLS.Extra
    import System.IO
    import Text.Printf
 
    server = "smtp.gmail.com"
    port   = 25 --that has to chage, I think

    forever a = a >> forever a

    main = test1
 
    write :: Handle -> String -> IO ()
    write h s  = do
        hPrintf h "%s\r\n" s
        printf    "> %s\n" s
 
    listen :: Handle -> IO () 
    listen h = forever $ hGetLine h >>= putStrLn

    test1 = do h <- connectTo server (PortNumber (fromIntegral port))
               hSetBuffering h NoBuffering
               write h "EHLO"
               write h "STATTLS"
               listen h

Another thing is that I use the listen function to know what is going on. 
But I cannot figure out how to use it along with write. 
That is to say, I would like to be able to see what is going on server-side 
while sending some data.

I found two functions that may resolve my problems: 

connectionClient :: CryptoRandomGen g => String -> String -> TLSParams -> g -> IO (TLSCtx Handle)
forkIO :: IO () -> IO ThreadId

The first for tls and the second to send and receive at the same time.
But can't seem to make them work.

I hope I am not to messy here, any help would be appreciated.

PS: English is not my native.

-- 
Sarfraz K.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120703/38a89389/attachment.pgp>


More information about the Beginners mailing list