View Source smtp (util v1.1.5)
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"}]).
Link to this section Summary
Types
Protocol type.
SNMP Options
- Server - server to connect to (no MX lookup)
- Relay - domain to do MX lookup of list of servers
- Port - optional port number (ssl def: 465; tcp def: 25)
- Auth - controls mandatory / optional authentication
- Tls - controls enabling of TLS protocol
- Domain - name of the domain to include in the HELO handshake
- Timeout - timeout to use (default 10000)
- Verbose - controls debugging printout
- Attachments - list of files to attach
- SSLOpts - additional SSL options if using SSL protocol
Functions
Get domain that this host belongs to.
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 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.
Link to this section Types
-type proto() :: tcp | ssl.
-type 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()}]}].
- Server - server to connect to (no MX lookup)
- Relay - domain to do MX lookup of list of servers
- Port - optional port number (ssl def: 465; tcp def: 25)
- Auth - controls mandatory / optional authentication
- Tls - controls enabling of TLS protocol
- Domain - name of the domain to include in the HELO handshake
- Timeout - timeout to use (default 10000)
- Verbose - controls debugging printout
- Attachments - list of files to attach
- SSLOpts - additional SSL options if using SSL protocol
Link to this section Functions
-spec domain() -> binary().
-spec send(Proto :: proto(), From :: string() | binary(), To :: string() | binary(), Subj :: string() | binary(), Msg :: string() | binary()) -> ok.
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.
-spec send(Proto :: proto(), From :: string() | binary(), To :: string() | binary(), Subj :: string() | binary(), Msg :: string() | binary(), Opts :: smtp_options()) -> ok.