Posts tagged ‘erlmail’

There’s very good erlang library with email services – erlmail. Unfortunately there’s no support to authorization in it – you can easy add this feature to library by this patch ( erlmail with authorization )
Here’s an example of using erlmail to send e-mail:

send_mail(UserEmail, Data) ->
    {ok, Pid} = smtpc:connect(“”, ?SMTP_PORT),
    smtpc:ehlo(Pid, ?SMTP_SERVER),
    smtpc:auth(Pid, ?MAIL_LOGIN, ?MAIL_PASSWORD),
    smtpc:mail(Pid, ?MAIL_FROM),
    smtpc:rcpt(Pid, UserEmail),
    smtpc:data(Pid, Data),

send_mail(UserEmail, MessageSubject, MessageBody) ->
    Data = “From:” ++ ?MAIL_FROM ++ “\r\n” ++ “To:” ++ UserEmail ++ “\r\n” ++ “Subject:” ++
MessageSubject ++ “\r\n\r\n” ++ MessageBody,
    send_mail(UserEmail, Data ).

test() ->
    send_mail(“”, “this is subject”, “this is message body!”).