smtp (util v1.3.5)
View SourceSMTP 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"}]).Author: Johan Bevemyr, Serge Aleynikov saleyn@gmail.com
Summary
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.
Types
-type proto() :: tcp | ssl.
Protocol type.
-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()}]}].
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
-spec domain() -> binary().
Get domain that this host belongs to.
-spec 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.
-spec 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.