View Source Mua (Mua v0.2.3)
Minimal SMTP client.
Summary
Functions
Sends AUTH
extension command and authenticates the sender.
Closes connection to the SMTP server.
Connects to an SMTP server and receives its banner.
Sends DATA
command that specifies the beginning of the mail, and then sends the message.
Utility function to send a message to a list of recipients on a host.
Sends EHLO
command which provides the identification of the sender i.e. the host name,
and receives the list of extensions the server supports.
Sends HELO
command which provides the identification of the sender i.e. the host name.
Sends MAIL FROM
command that specifies the originator of the mail.
Utility function to lookup MX servers for a domain.
Sends NOOP
command that does nothing.
Utility function to pick a supported auth method from a list of extensions.
Sends QUIT
command that make the server close the connection.
Sends RCPT TO
command that specify the recipient of the mail.
Sends RSET
command that aborts the current mail transaction but keeps the socket open.
Sends STARTTLS
extension command and starts TLS session negotiation.
Sends VRFY
command that confirms or verifies the user name.
Types
@type auth_method() :: :login | :plain
@type error() :: {:error, Mua.SMTPError.t() | Mua.TransportError.t()}
@type host() :: :inet.socket_address() | :inet.hostname() | String.t()
@type option() :: {:timeout, timeout()} | {:mx, boolean()} | {:protocol, :tcp | :ssl} | {:auth, auth_credentials()} | {:port, :inet.port_number()} | {:tcp, [:gen_tcp.connect_option()]} | {:ssl, [:ssl.tls_client_option()]}
@type socket() :: :gen_tcp.socket() | :ssl.sslsocket()
Functions
@spec auth(socket(), auth_method(), auth_credentials(), timeout()) :: :ok | error()
Sends AUTH
extension command and authenticates the sender.
:ok = auth(socket, :login, username: username, password: password)
:ok = auth(socket, :plain, username: username, password: password)
@spec close(socket()) :: :ok | {:error, Mua.TransportError.t()}
Closes connection to the SMTP server.
:ok = close(socket)
@spec connect( :tcp, host(), :inet.port_number(), [:gen_tcp.connect_option()], timeout() ) :: {:ok, :gen_tcp.socket(), banner :: String.t()} | error()
@spec connect( :ssl, host(), :inet.port_number(), [:ssl.tls_client_option()], timeout() ) :: {:ok, :ssl.sslsocket(), banner :: String.t()} | error()
Connects to an SMTP server and receives its banner.
{:ok, socket, _banner} = connect(:tcp, host, _port = 25)
{:ok, socket, _banner} = connect(:ssl, host, _port = 465, versions: [:"tlsv1.3"])
Sends DATA
command that specifies the beginning of the mail, and then sends the message.
{:ok, _receipt} = data(socket, "Date: Sat, 24 Jun 2023 13:43:57 +0000\r\n...")
@spec easy_send(String.t() | :inet.ip_address(), String.t(), [String.t()], iodata(), [ option() ]) :: {:ok, receipt :: String.t()} | error()
Utility function to send a message to a list of recipients on a host.
{:ok, _receipt} =
easy_send(
_host = "gmail.com",
_sender = "mua@github.com",
_recipients = ["support@gmail.com"],
_message = "Date: Sat, 24 Jun 2023 13:43:57 +0000\r\n..."
)
Sends EHLO
command which provides the identification of the sender i.e. the host name,
and receives the list of extensions the server supports.
{:ok, _extensions = ["STARTTLS" | _rest]} = ehlo(socket, _our_hostname = "copycat.fun")
Sends HELO
command which provides the identification of the sender i.e. the host name.
:ok = helo(socket, _our_hostname = "copycat.fun")
Sends MAIL FROM
command that specifies the originator of the mail.
:ok = mail_from(socket, "hey@copycat.fun")
Utility function to lookup MX servers for a domain.
["gmail-smtp-in.l.google.com" | _rest] = mxlookup("gmail.com")
Sends NOOP
command that does nothing.
:ok = noop(socket)
@spec pick_auth_method([String.t()]) :: auth_method() | nil
Utility function to pick a supported auth method from a list of extensions.
{:ok, extensions} = ehlo(socket, hostname)
maybe_method = pick_auth_method(extensions)
true = maybe_method in [nil, :plain, :login]
Sends QUIT
command that make the server close the connection.
:ok = quit(socket)
Sends RCPT TO
command that specify the recipient of the mail.
:ok = rcpt_to(socket, "world@hey.com")
Sends RSET
command that aborts the current mail transaction but keeps the socket open.
:ok = rset(socket)
@spec starttls(:ssl.socket(), host(), [:ssl.tls_client_option()], timeout()) :: {:ok, :ssl.sslsocket()} | error()
Sends STARTTLS
extension command and starts TLS session negotiation.
{:ok, sslsocket} = starttls(socket, host, versions: [:"tlsv1.3"], middlebox_comp_mode: false)
Sends VRFY
command that confirms or verifies the user name.
{:ok, true} = vrfy(socket, "dogaruslan@gmail.com")