module Network.Smtp.Simple
(
SendMail(..),
defSendMail,
sendMail,
sendMail_
)
where
import Control.ContStuff
import Control.Exception.Peel
import Data.Enumerator
import Network.Smtp.Monad
import Network.Smtp.Tools
import Network.Smtp.Types
import System.IO
data SendMail =
SendMail {
mailBufferSize :: Int,
mailInputHandle :: Handle,
mailMaxLine :: Int,
mailMaxMessages :: Int,
mailOutputHandle :: Handle,
mailTimeout :: Int
}
defSendMail :: Handle -> Handle -> SendMail
defSendMail inH outH =
SendMail { mailBufferSize = 4096,
mailInputHandle = inH,
mailMaxLine = 512,
mailMaxMessages = 128,
mailOutputHandle = outH,
mailTimeout = 60000 }
sendMail :: (Applicative m, MonadIO m) =>
SendMail -> MailT (Either SomeException a) m a ->
m (Either SomeException a)
sendMail cfg c =
let SendMail { mailBufferSize = bufSize,
mailInputHandle = inH,
mailMaxLine = maxLine,
mailMaxMessages = maxMsgs,
mailOutputHandle = outH,
mailTimeout = timeout } = cfg
in runMailT outH (enumHandleTimeout bufSize timeout inH $$
responseLines maxLine maxMsgs c)
sendMail_ :: (Applicative m, MonadIO m) =>
SendMail -> MailT (Either SomeException a) m a ->
m a
sendMail_ cfg = sendMail cfg >=> either throwIO return