Module smtp

Authors: Johan Bevemyr, Serge Aleynikov (saleyn@gmail.com).

Description

SMTP mail client. This module can sent emails to one or more recipients, using primary/backup SMTP servers. Messages can contain attachments.

   Example:
       % Send a message to two recipients with a file attachment using
       % SSL protocol at mail server "mail.bevemyr.com":
       smtp:send(ssl, "Alex <jb@bevemyr.com>",
                 ["katrin@bevemyr.com","jb@bevemyr.com"],
                 "Test Subject", "My Message",
                 [{server, "mail.bevemyr.com"},
                  {username, "alex"}, {password, "secret"},
                  {attachments, ["file1.txt"]}]).
  
       % Send a message to a recipient with a file attachment given custom
       % MIME type using localhost mail server
       smtp:send(tcp, "jb@bevemyr.com",
                 ["katrin@bevemyr.com"], "Test Subject", "My Message",
                 [{server, "mail.bevemyr.com"},
                  {username, "alex"}, {password, "secret"},
                  {attachments, [{"file1.bin","application/custom_MIME"}]}]).
  
       % Send a message to two recipients with an attachment given as list
       smtp:send(tcp, "jb@bevemyr.com",
                 ["katrin@bevemyr.com","jb@bevemyr.com"],
                 "Test Subject", "My Message",
                 [{"file1.txt","text/plain","Attachment past as list"}]).

Data Types

proto()

proto() = tcp | ssl

Protocol type.

smtp_options()

smtp_options() = 
    [{server, Server :: string()} |
     {relay, Relay :: string()} |
     {port, Port :: integer()} |
     {auth, Auth :: always | never} |
     {username, Username :: string()} |
     {password, Password :: string()} |
     {tls, Tls :: always | if_available} |
     {domain, Domain :: string()} |
     {timeout, Millisec :: integer()} |
     {verbose, debug} |
     {ssl, SSLOpts :: list()} |
     {attachments,
      [Filename ::
           string() |
           {Filename :: string(), ContentType :: string()} |
           {Filename :: string(),
            ContentType :: string(),
            Data :: list()}]}]

SNMP Options

Function Index

domain/0Get domain that this host belongs to.
send/5Send a message to a list of To receipients using localhost.
send/6Send a message to a list of recipients by connecting to an SMTP server Server.

Function Details

domain/0

domain() -> binary()

Get domain that this host belongs to.

send/5

send(Proto :: proto(),
     From :: string() | binary(),
     To :: string() | binary(),
     Subj :: string() | binary(),
     Msg :: string() | binary()) ->
        ok

Send a message to a list of To receipients using localhost. Error is thrown if unable to send a message. Use inet:format_error/1 to decode the Reason if it is an atom.

send/6

send(Proto :: proto(),
     From :: string() | binary(),
     To :: string() | binary(),
     Subj :: string() | binary(),
     Msg :: string() | binary(),
     Opts :: smtp_options()) ->
        ok

Send a message to a list of recipients by connecting to an SMTP server Server. The message can contain attachments in the Attachments list. See examples on the top of this page. Error is thrown if unable to send a message.