Module gen_smtp_client

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

Description

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

Data Types

callback()

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

email()

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

email_address()

email_address() = string() | binary()

failure()

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

host_failure()

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()}}

options()

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())}]

permanent_failure_reason()

permanent_failure_reason() = binary() | auth_failed | ssl_not_started

smtp_client_socket()

abstract datatype: smtp_client_socket()

smtp_host()

smtp_host() = inet:hostname()

smtp_session_error()

smtp_session_error() = {error, no_more_hosts | send, {permanent_failure, smtp_host(), permanent_failure_reason()}} | {error, retries_exceeded | send, host_failure()}

temporary_failure_reason()

temporary_failure_reason() = binary() | tls_failed

validate_options_error()

validate_options_error() = no_relay | invalid_port | no_credentials

Function Index

close/1Close an open smtp client socket opened with open/1.
deliver/2Deliver an email on an open smtp client socket.
open/1Open a SMTP client socket with the provided options Once the socket has been opened, you can use it with deliver/2.
send/2Send an email in a non-blocking fashion via a spawned_linked process.
send/3Send an email nonblocking and invoke a callback with the result of the send.
send_blocking/2Send an email and block waiting for the reply.

Function Details

close/1

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

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

deliver/2

deliver(Socket::smtp_client_socket(), Email::email()) -> {ok, Receipt::binary()} | {error, 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}.

open/1

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.

send/2

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.

send/3

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 identifier, {error, Type, Message} or {exit, ExitReason}, as the single argument.

send_blocking/2

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

Send an email and block waiting for the reply. Returns either a binary that contains the SMTP server's receipt or {error, Type, Message} or {error, Reason}.


Generated by EDoc