View Source gen_smtp_client (gen_smtp v1.3.0)

A simple SMTP client used for sending mail - assumes relaying via a smarthost.

Link to this section Summary

Functions

Close an open smtp client socket opened with open/1.

Deliver an email on an open smtp client socket. For use with a socket opened with open/1. The socket can be reused as long as the previous call to deliver/2 returned {ok, Receipt}. If it's using LMTP protocol, it will return a list with the delivery response for each address {ok, [{"foo@bar.com", "250 ok"}, {"bar@foo.com", "452 <bar@foo.com> is temporarily over quota"}]}`. If the previous call to deliver/2 returned `{error, FailMsg} and the option {on_transaction_error, reset} was given in the open/1 call, the socket may still be reused.

Open a SMTP client socket with the provided options Once the socket has been opened, you can use it with deliver/2.

Send an email in a non-blocking fashion via a spawned_linked process. The process will exit abnormally on a send failure.

Send an email nonblocking and invoke a callback with the result of the send. The callback will receive either {ok, Receipt} where Receipt is the SMTP server's receipt If it's using LMTP protocol, the callback will receive a list with the delivery response for each address {ok, [{"foo@bar.com", "250 ok"}, {"bar@foo.com", "452 <bar@foo.com> is temporarily over quota"}]}`. identifier, `{error, Type, Message} or {exit, ExitReason}, as the single argument.

Send an email and block waiting for the reply. Returns either a binary that contains If it's using LMTP protocol, it will return a list with the delivery response for each address [{"foo@bar.com", "250 ok"}, {"bar@foo.com", "452 <bar@foo.com> is temporarily over quota"}]`. the SMTP servers receipt or {error, Type, Message} or {error, Reason}.

Link to this section Types

Specs

callback() :: fun(({exit, any()} | smtp_session_error() | {ok, binary()}) -> any()).

Specs

email() ::
    {From :: email_address(),
     To :: [email_address(), ...],
     Body :: string() | binary() | fun(() -> string() | binary())}.

Specs

email_address() :: string() | binary().

Specs

extensions() :: [{binary(), binary()}].

Specs

failure() ::
    {temporary_failure, temporary_failure_reason()} |
    {permanent_failure, permanent_failure_reason()} |
    {missing_requirement, auth | tls} |
    {unexpected_response, [binary()]} |
    {network_failure, {error, timeout | inet:posix()}}.

Specs

host_failure() ::
    {temporary_failure, smtp_host(), temporary_failure_reason()} |
    {permanent_failure, smtp_host(), permanent_failure_reason()} |
    {missing_requirement, smtp_host(), auth | tls} |
    {unexpected_response, smtp_host(), [binary()]} |
    {network_failure, smtp_host(), {error, timeout | inet:posix()}}.

Specs

options() ::
    [{ssl, boolean()} |
     {tls, always | never | if_available} |
     {tls_options, list()} |
     {sockopts, [gen_tcp:connect_option()]} |
     {port, inet:port_number()} |
     {timeout, timeout()} |
     {relay, inet:ip_address() | inet:hostname()} |
     {no_mx_lookups, boolean()} |
     {auth, always | never | if_available} |
     {hostname, string()} |
     {retries, non_neg_integer()} |
     {username, string()} |
     {password, string()} |
     {trace_fun, fun((Fmt :: string(), Args :: [any()]) -> any())} |
     {on_transaction_error, quit | reset} |
     {protocol, smtp | lmtp}].
Link to this type

permanent_failure_reason/0

View Source

Specs

permanent_failure_reason() :: binary() | auth_failed | ssl_not_started.

server's 4xx response

Link to this opaque

smtp_client_socket/0

View Source (opaque)

Specs

smtp_client_socket()

Specs

smtp_host() :: inet:hostname().

Specs

smtp_session_error() ::
    {error, no_more_hosts | send, {permanent_failure, smtp_host(), permanent_failure_reason()}} |
    {error, retries_exceeded | send, host_failure()}.
Link to this type

temporary_failure_reason/0

View Source

Specs

temporary_failure_reason() :: binary() | tls_failed.
Link to this type

validate_options_error/0

View Source

Specs

validate_options_error() :: no_relay | invalid_port | no_credentials.

Link to this section Functions

Specs

close(Socket :: smtp_client_socket()) -> ok.

Close an open smtp client socket opened with open/1.

Specs

deliver(Socket :: smtp_client_socket(), Email :: email()) ->
           {ok, Receipt :: binary() | [{binary(), binary()}, ...]} | {error, FailMsg :: failure()}.

Deliver an email on an open smtp client socket. For use with a socket opened with open/1. The socket can be reused as long as the previous call to deliver/2 returned {ok, Receipt}. If it's using LMTP protocol, it will return a list with the delivery response for each address {ok, [{"foo@bar.com", "250 ok"}, {"bar@foo.com", "452 <bar@foo.com> is temporarily over quota"}]}`. If the previous call to deliver/2 returned `{error, FailMsg} and the option {on_transaction_error, reset} was given in the open/1 call, the socket may still be reused.

Specs

open(Options :: options()) ->
        {ok, SocketDescriptor :: smtp_client_socket()} |
        smtp_session_error() |
        {error, bad_option, validate_options_error()}.

Open a SMTP client socket with the provided options Once the socket has been opened, you can use it with deliver/2.

Specs

send(Email :: email(), Options :: options()) -> {ok, pid()} | {error, validate_options_error()}.

Send an email in a non-blocking fashion via a spawned_linked process. The process will exit abnormally on a send failure.

Link to this function

send(Email, Options, Callback)

View Source

Specs

send(Email :: email(), Options :: options(), Callback :: callback() | undefined) ->
        {ok, pid()} | {error, validate_options_error()}.

Send an email nonblocking and invoke a callback with the result of the send. The callback will receive either {ok, Receipt} where Receipt is the SMTP server's receipt If it's using LMTP protocol, the callback will receive a list with the delivery response for each address {ok, [{"foo@bar.com", "250 ok"}, {"bar@foo.com", "452 <bar@foo.com> is temporarily over quota"}]}`. identifier, `{error, Type, Message} or {exit, ExitReason}, as the single argument.

Link to this function

send_blocking(Email, Options)

View Source

Specs

send_blocking(Email :: email(), Options :: options()) ->
                 binary() |
                 [{binary(), binary()}, ...] |
                 smtp_session_error() |
                 {error, validate_options_error()}.

Send an email and block waiting for the reply. Returns either a binary that contains If it's using LMTP protocol, it will return a list with the delivery response for each address [{"foo@bar.com", "250 ok"}, {"bar@foo.com", "452 <bar@foo.com> is temporarily over quota"}]`. the SMTP servers receipt or {error, Type, Message} or {error, Reason}.