NAME
msmtp - An SMTP client
SYNOPSIS
Sendmail mode (default):
msmtp [option...] [--] recipient...
msmtp [option...] -t [--] [recipient...]
Server information mode:
msmtp [option...] --serverinfo
Remote Message Queue Starting mode:
msmtp [option...] --rmqs=host|@domain|#queue
DESCRIPTION
In the default sendmail mode, msmtp reads a mail from standard input
and sends it to an SMTP server for delivery.
In server information mode, msmtp prints information about an SMTP
server.
In Remote Message Queue Starting mode, msmtp sends a Remote Message
Queue Starting request for a host, domain, or queue to an SMTP server.
EXIT STATUS
The standard sendmail exit status codes are used, as defined in
sysexits.h.
OPTIONS
Options override configuration file settings.
They are compatible with sendmail where appropriate.
General options
--version
Print version information. This includes information
about the library used for TLS/SSL support (if any), the
library used for authentication, the authentication
mechanisms supported by this library, and the default
locations of the system and user configuration files.
--help Print help.
-P, --pretend
Print the configuration settings that would be used, but
do not take further action. An asterisk (‘*’) will be
printed instead of your password.
-v, -d, --debug
Print lots of debugging information, including the whole
conversation with the SMTP server. Be careful with this
option: the (potentially dangerous) output will not be
sanitized, and your password may get printed in an easily
decodable format!
Changing the mode of operation
-S, --serverinfo
Print information about the SMTP server and exit. This
includes information about supported features (mail size
limit, authentication, TLS, DSN, ...) and about the TLS
certificate (if TLS is active).
--rmqs=(host|@domain|#queue)
Send a Remote Message Queue Starting request for the
given host, domain, or queue to the SMTP server and exit.
Configuration options
-C, --file=filename
Use the given file instead of ~/.msmtprc as the user
configuration file.
-a, --account=account_name
Use the given account instead of the account named
"default". The settings of this account may be changed
with command line options. This option cannot be used
together with the --host option.
--host=hostname
Use this SMTP server with settings from the command line;
do not use any configuration file data. This option
cannot be used together with the --account option.
--port=number
Set the port number to connect to. See the port command
below.
--timeout=(off|seconds)
Set a network timeout. See the timeout command below. For
compatibility with older versions, --connect-timeout is
accepted as an alias for this option.
--protocol=(smtp|lmtp)
Set the protocol to use. See the protocol command below.
--auth[=(on|off|method)]
Enable or disable authentication. You can optionally
choose the method. See the auth command below.
--user=[username]
Set or unset the user name for authentication. See the
user command below.
--tls[=(on|off)]
Enable or disable TLS/SSL encryption. See the tls command
below.
--tls-starttls[=(on|off)]
Enable or disable STARTTLS for TLS encryption. See the
tls_starttls command below.
--tls-trust-file=[file]
Set or unset a trust file for TLS encryption. See the
tls_trust_file command below.
--tls-crl-file=[file]
Set or unset a certificate revocation list (CRL) file for
TLS. See the tls_crl_file command below.
--tls-fingerprint=[fingerprint]
Set ot unset the fingerprint of a trusted TLS
certificate. See the tls_fingerprint command below.
--tls-key-file=[file]
Set or unset a key file for TLS encryption. See the
tls_key_file command below.
--tls-cert-file=[file]
Set or unset a cert file for TLS encryption. See the
tls_cert_file command below.
--tls-certcheck[=(on|off)]
Enable or disable server certificate checks for TLS
encryption. See the tls_certcheck command below.
--tls-force-sslv3[=(on|off)]
Force TLS/SSL version SSLv3. See the tls_force_sslv3
command below.
--tls-min-dh-prime-bits=[bits]
Set or unset minimum bit size of the Diffie-Hellman (DH)
prime. See the tls_min_dh_prime_bits command below.
--tls-priorities=[priorities]
Set or unset TLS priorities. See the tls_priorities
command below.
--domain=[string]
Set the argument of the SMTP EHLO (or LMTP LHLO) command.
See the domain command below.
Options specific to sendmail mode
--auto-from[=(on|off)]
Enable or disable automatic envelope-from addresses. The
default is off. See the auto_from command below.
-f, --from=address
Set the envelope-from address. It is only used when
auto_from is off.
If no account was chosen yet (with --account or --host),
this option will choose the first account that has the
given envelope-from address (set with the from command).
If no such account is found, "default" is used.
--maildomain=[domain]
Set the domain part for generated envelope-from
addresses. It is only used when auto_from is on. See the
maildomain command below.
-N, --dsn-notify=(off|cond)
Set or unset DSN notification conditions. See the
dsn_notify command below.
-R, --dsn-return=(off|ret)
Set or unset the DSN notification amount. See the
dsn_return command below. Note that hdrs is accepted as
an alias for headers to be compatible with sendmail.
--keepbcc[=(on|off)]
Enable or disable the preservation of the Bcc header. See
the keepbcc command below.
-X, --logfile=[file]
Set or unset the log file. See the logfile command below.
--syslog[=(on|off|facility)]
Enable or disable syslog logging. See the syslog command
below.
-t, --read-recipients
Read recipient addresses from the To, Cc, and Bcc headers
of the mail in addition to the recipients given on the
command line. If any Resent- headers are present, then
the addresses from any Resent-To, Resent-Cc, and Resent-
Bcc headers in the first block of Resent- headers are
used instead.
--read-envelope-from
Read the envelope from address from the From header of
the mail.
-- This marks the end of options. All following arguments
will be treated as recipient addresses, even if they
start with a ‘-’.
The following options are accepted but ignored for sendmail
compatibility:
-Btype, -bm, -Fname, -G, -hN, -i, -L tag, -m, -n, -O option=value, -ox
value
USAGE
Normally, a system wide configuration file and/or a user configuration
file contain information about which SMTP server to use (and how to use
it), but almost all settings can also be configured on the command
line.
Information about SMTP servers is organized in accounts. Each account
describes one SMTP server: host name, authentication settings, TLS
settings, and so on. Each configuration file can define multiple
accounts.
In sendmail mode, an envelope-from address is necessary to send mail.
This is the mail address that will be presented to the SMTP server as
the originator of the mail. Envelope-from addresses can be generated
automatically (when auto_from is enabled) or set explicitly with the
from command or --from option. When auto_from is enabled, an envelope-
from address of the form user@domain will be generated. The local part
will be set to USER or, if that fails, to LOGNAME or, if that fails, to
the login name of the current user. The domain part can be set with
the maildomain command. If the maildomain is empty, the envelope-from
address will only consist of the user name and not have a domain part.
The user can choose which account to use in one of three ways:
--account=id
Use the given account. Command line settings override
configuration file settings.
--host=hostname
Use only the settings from the command line; do not use any
configuration file data.
--from=address or --read-envelope-from
Choose the first account from the system or user configuration
file that has a matching envelope-from address as specified by a
from command. This works only when neither --account nor --host
is used.
If none of the above options is used (or if no account has a matching
from command), then the account "default" is used.
Skip to the EXAMPLES section for a quick start.
CONFIGURATION FILES
If it exists and is readable, a system wide configuration file
SYSCONFDIR/msmtprc will be loaded, where SYSCONFDIR depends on your
platform. Use --version to find out which directory is used.
If it exists and is readable, a user configuration file will be loaded
(~/.msmtprc by default). Accounts defined in the user configuration
file override accounts from the system configuration file. The user
configuration file must have no more permissions than user read/write.
Configuration data from either file can be changed by command line
options.
A configuration file is a simple text file. Empty lines and comment
lines (whose first non-blank character is ‘#’) are ignored.
Every other line must contain a command and may contain an argument to
that command.
The argument may be enclosed in double quotes ("), for example if its
first or last character is a blank.
If the first character of a filename is the tilde (~), this tilde will
be replaced by HOME. If a command accepts the argument on, it also
accepts an empty argument and treats that as if it was on.
Commands form groups. Each group begins with the account command and
defines the settings for one SMTP server.
Skip to the EXAMPLES section for a quick start.
Commands are as follows:
defaults
Set defaults. The following configuration commands will set
default values for all following account definitions in the
current configuration file.
account name [:account[,...]]
Start a new account definition with the given name. The current
default values are filled in.
If a colon and a list of previously defined accounts is given
after the account name, the new account, with the filled in
default values, will inherit all settings from the accounts in
the list.
host hostname
The SMTP server to send the mail to. The argument may be a host
name or a network address. Every account definition must
contain this command.
port number
The port that the SMTP server listens on. The default port will
be acquired from your operating system’s service database: for
SMTP, the service is "smtp" (default port 25), unless TLS
without STARTTLS is used, in which case it is "ssmtp" (465). For
LMTP, it is "lmtp".
timeout (off|seconds)
Set or unset a network timeout, in seconds. The argument off
means that no timeout will be set, which means that the
operating system default will be used.
For compatibility with older versions, connect_timeout is
accepted as an alias for this command.
protocol (smtp|lmtp)
Set the protocol to use. Currently only SMTP and LMTP are
supported. SMTP is the default. See the port command above for
default ports.
auto_from [(on|off)]
Enable or disable automatic envelope-from addresses. The default
is off. When enabled, an envelope-from address of the form
user@domain will be generated. The local part will be set to
USER or, if that fails, to LOGNAME or, if that fails, to the
login name of the current user. The domain part can be set with
the maildomain command. If the maildomain is empty, the
envelope-from address will only consist of the user name and not
have a domain part. When auto_from is disabled, the envelope-
from address must be set explicitly.
from envelope_from
Set the envelope-from address. This address will only be used
when auto_from is off.
maildomain [domain]
Set a domain part for the generation of an envelope-from
address. This is only used when auto_from is on. The domain may
be empty.
auth [(on|off|method)]
This command enables or disables SMTP authentication. You should
not need to set the method yourself; with the argument on, msmtp
will choose the best one available for you (see below).
You probably need to set a username (with user) and password
(with password). If no password is set but one is needed during
authentication, msmtp will try to find it in ~/.netrc. If that
fails, it will try to find it in SYSCONFDIR/netrc (use --version
to find out what SYSCONFDIR is on your platform). If that fails,
it will try to get it from a system specific keyring (if
available). If that fails but a controlling terminal is
available, msmtp will prompt you for it.
Currently supported keyrings are the Gnome Keyring and the Mac
OS X Keychain. The script msmtp-gnome-tool.py can be used to
manage Gnome Keyring passwords for msmtp. To manage Mac OS X
Keychain passwords, use the Keychain Access GUI application. The
account name is same as the msmtp user argument. The keychain
item name is smtp://<hostname> where <hostname> matches the
msmtp host argument.
Available authentication methods are plain, cram-md5,
digest-md5, scram-sha-1, gssapi, external, login, and ntlm.
Note that one or more of these methods may be unavailable due to
lack of support in the underlying authentication library. Use
the --version option to find out which methods are supported.
The plain and login methods send your authentication data in
cleartext over the net, and the ntlm method may be vulnerable to
attacks. These methods should therefore only be used together
with the tls command.
If you don’t choose the method yourself, msmtp chooses the best
secure method that the SMTP server supports. Secure means that
your authentication data will not be sent in cleartext over the
net. For TLS encrypted connections, every authentication method
is secure in this sense. If TLS is not active, only gssapi,
scram-sha-1, digest-md5, and cram-md5 are secure in this sense.
The external is special: the actual authentication happens
outside of the SMTP protocol, typically by sending a TLS client
certificate (see the tls_cert_file command). The external method
merely confirms that this authentication succeeded for the given
user (or, if no user name is given, confirms that authentication
succeeded). This authentication method is not chosen
automatically; you have to request it manually.
user [username]
Set your user name for SMTP authentication. An empty argument
unsets the user name. Authentication must be activated with the
auth command.
password [secret]
Set your password for SMTP authentication. An empty argument
unsets the password. Authentication must be activated with the
auth command. If no password is set but one is needed during
authentication, msmtp will try to find it in ~/.netrc. If that
fails, it will try to find it in SYSCONFDIR/netrc (use --version
to find out what SYSCONFDIR is on your platform). If that fails,
it will try to get it from a system specific keychain (if
available). If that fails but a controlling terminal is
available, msmtp will prompt you for it.
ntlmdomain [domain]
Set a domain for the ntlm authentication method. The default is
to use no domain (equivalent to an empty argument), but some
servers seem to require one, even if it is an arbitrary string.
tls [(on|off)]
This command enables or disables TLS (also known as SSL)
encrypted connections to the SMTP server. Not every server
supports TLS.
With TLS/SSL, the connection with the SMTP server will be
protected against eavesdroppers and man-in-the-middle attacks.
To use TLS/SSL, it is required to either use the tls_trust_file
command (highly recommended) or to disable tls_certcheck.
tls_starttls [(on|off)]
By default, TLS encryption is activated using the STARTTLS SMTP
command. By disabling this, TLS encryption is immediately
started instead (this is known as SMTP tunneled through
TLS/SSL). The default port is set to 465 for this mode of
operation.
For compatibility with older versions, tls_nostarttls is
accepted as an alias for tls_starttls off.
tls_trust_file [file]
This command activates strict server certificate verification.
The filename must be the absolute path name of a file in PEM
format containing one or more certificates of trusted
Certification Authorities (CAs).
On Debian based systems, you can install the ca-certificates
package and use the file /etc/ssl/certs/ca-certificates.crt.
tls_crl_file [file]
This command sets or unsets a certificate revocation list (CRL)
file for TLS, to be used during strict server certificate
verification as enabled by the tls_trust_file command. This
allows the verification procedure to detect revoked
certificates.
tls_fingerprint [fingerprint]
This command sets or unsets the fingerprint of a particular TLS
certificate. This certificate will then be trusted, regardless
of its contents. This can be used to trust broken certificates
(e.g. with a non-matching hostname) or in situations where
tls_trust_file cannot be used for some reason.
You can give either an SHA1 (recommended) or an MD5 fingerprint
in the format 01:23:45:67:...
You can use --serverinfo --tls --tls-certcheck=off to get the
peer certificate’s fingerprints.
tls_key_file [file]
This command (together with the tls_cert_file command) enables
msmtp to send a client certificate to the SMTP server if
requested. The file must contain the private key of a
certificate in PEM format. An empty argument disables this
feature.
tls_cert_file [file]
This command (together with the tls_key_file command) enables
msmtp to send a client certificate to the SMTP server if
requested. The file must contain a certificate in PEM format.
An empty argument disables this feature.
tls_certcheck [(on|off)]
This command enables or disables checks for the server
certificate.
WARNING: When the checks are disabled, TLS/SSL sessions will be
vulnerable to man-in-the-middle attacks!
For compatibility with older versions, tls_nocertcheck is
accepted as an alias for tls_certcheck off.
tls_force_sslv3 [(on|off)]
Force TLS/SSL version SSLv3. This might be needed to use SSL
with some old and broken servers. Do not use this unless you
have to.
tls_min_dh_prime_bits [bits]
Set or unset the minimum number of Diffie-Hellman (DH) prime
bits that msmtp will accept for TLS sessions. The default is
set by the TLS library and can be selected by using an empty
argument to this command. Only lower the default (for example
to 512 bits) if there is no other way to make TLS work with the
remote server.
tls_priorities [priorities]
Set the priorities for TLS sessions. The default is set by the
TLS library and can be selected by using an empty argument to
this command. Currently this command only works with
sufficiently recent GnuTLS releases. See the GnuTLS
documentation of the gnutls_priority_init function for a
description of the priorities string.
dsn_notify (off|condition)
This command sets the condition(s) under which the mail system
should send DSN (Delivery Status Notification) messages. The
argument off disables explicit DSN requests, which means the
mail system decides when to send DSN messages. This is the
default. The condition must be never, to never request
notification, or a comma separated list (no spaces!) of one or
more of the following: failure, to request notification on
transmission failure, delay, to be notified of message delays,
success, to be notified of successful transmission. The SMTP
server must support the DSN extension.
dsn_return (off|amount)
This command controls how much of a mail should be returned in
DSN (Delivery Status Notification) messages. The argument off
disables explicit DSN requests, which means the mail system
decides how much of a mail it returns in DSN messages. This is
the default. The amount must be headers, to just return the
message headers, or full, to return the full mail. The SMTP
server must support the DSN extension.
domain argument
Use this command to set the argument of the SMTP EHLO (or LMTP
LHLO) command. The default is localhost (stupid, but working).
Possible choices are the domain part of your mail address
(provider.example for joe@provider.example) or the fully
qualified domain name of your host (if available).
keepbcc [(on|off)]
This command controls whether to remove or keep the Bcc header
when sending a mail. The default is to remove it.
logfile [file]
An empty argument disables logging (this is the default).
When logging is enabled by choosing a log file, msmtp will
append one line to the log file for each mail it tries to send
via the account that this log file was chosen for.
The line will include the following information: date and time,
host name of the SMTP server, whether TLS was used, whether
authentication was used, authentication user name (only if
authentication is used), envelope-from address, recipient
addresses, size of the mail as transferred to the server (only
if the delivery succeeded), SMTP status code and SMTP error
message (only in case of failure and only if available), error
message (only in case of failure and only if available), exit
code (from sysexits.h; EX_OK indicates success).
If the filename is a dash (-), msmtp prints the log line to the
standard output.
syslog [(on|off|facility)]
Enable or disable syslog logging. The facility can be one of
LOG_USER, LOG_MAIL, LOG_LOCAL0, ..., LOG_LOCAL7. The default is
LOG_USER.
Each time msmtp tries to send a mail via the account that
contains this syslog command, it will log one entry to the
syslog service with the chosen facility.
The line will include the following information: host name of
the SMTP server, whether TLS was used, whether authentication
was used, envelope-from address, recipient addresses, size of
the mail as transferred to the server (only if the delivery
succeeded), SMTP status code and SMTP error message (only in
case of failure and only if available), error message (only in
case of failure and only if available), exit code (from
sysexits.h; EX_OK indicates success).
EXAMPLES
Configuration file
# Set default values for all following accounts.
defaults
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
# A freemail service
account freemail
host smtp.freemail.example
from joe_smith@freemail.example
auth on
user joe.smith
password secret
# A second mail address at the same freemail service
account freemail2 : freemail
from joey@freemail.example
# The SMTP server of the provider.
account provider
host mail.provider.example
from smithjoe@provider.example
auth on
user 123456789
password my_password
# Set a default account
account default : provider
Manually finding the right CA certificate for tls_trust_file
The following example works as of 2007-04-18.
For the Gmail SMTP server, you first issue the following command:
msmtp --serverinfo --host=smtp.gmail.com --tls=on --port=587
--tls-certcheck=off
The option --port=587 is specific to Gmail and should not be used with
other servers. The option --tls-certcheck=off allows msmtp to accept
any certificate, so that it can print some information about it.
According to the output of this command, the common name of the server
certificate issuer is "Thawte Premium Server CA". This means that you
have to trust the Thawte CA to use full TLS security. You can download
the Thawte CA certificate bundle from http://thawte.com/roots. You get
a ZIP file with different certificates. The one you need for the
tls_trust_file command is Thawte Server
Roots/ThawtePremiumServerCA_b64.txt.
The following command should now succeed:
msmtp --serverinfo --host=smtp.gmail.com --tls=on --port=587
--tls-trust-file="Thawte Server Roots/ThawtePremiumServerCA_b64.txt"
Using msmtp with Mutt
Create a configuration file for msmtp and add the following lines to
your Mutt configuration file:
set sendmail="/path/to/msmtp"
set use_from=yes
set realname="Your Name"
set from=you@example.com
set envelope_from=yes
The envelope_from=yes option lets Mutt use the -f option of msmtp.
Therefore msmtp chooses the first account that matches the from address
you@example.com.
Alternatively, you can use the -a option:
set sendmail="/path/to/msmtp -a my-account"
Or set everything from the command line:
set sendmail="/path/to/msmtp --host=mailhub -f me@example.com --tls"
If you have multiple mail accounts in your msmtp configuration file and
let Mutt use the -f option to choose the right one, you can easily
switch accounts in Mutt with the following Mutt configuration lines:
macro generic "<esc>1" ":set from=you@example.com"
macro generic "<esc>2" ":set from=you@your-employer.example"
macro generic "<esc>3" ":set from=you@some-other-provider.example"
Using msmtp with mail
Define a default account, and put the following in your ~/.mailrc:
set sendmail="/path/to/msmtp"
FILES
SYSCONFDIR/msmtprc
System configuration file. Use --version to find out what
SYSCONFDIR is on your platform.
~/.msmtprc
User configuration file.
~/.netrc and SYSCONFDIR/netrc
The netrc file contains login information. If a password is not
found in the configuration file, msmtp will search it in
~/.netrc and SYSCONFDIR/netrc before prompting the user for it.
The syntax of netrc files is described in netrc(5) or ftp(1).
ENVIRONMENT
USER, LOGNAME
These variables override the user’s login name when constructing
an envelope-from address. LOGNAME is only used if USER is unset.
TMPDIR Directory to create temporary files in. If this is unset, a
system specific default directory is used.
A temporary file is only created when the -t/--read-recipients
or --read-envelope-from option is used. The file is then used to
buffer the headers of the mail (but not the body, so the file
won’t get very large).
EMAIL, SMTPSERVER
These environment variables are used only if neither --host nor
--account is used and there is no default account defined in the
configuration files. In this case, the host name is taken from
SMTPSERVER, and the envelope from address is taken from EMAIL,
unless overridden by --from or --read-envelope-from. Currently
SMTPSERVER must contain a plain host name (no URL), and EMAIL
must contain a plain address (no names or additional
information).
AUTHORS
msmtp was written by Martin Lambers <marlam@marlam.de>.
Other authors are listed in the AUTHORS file in the source
distribution.
SEE ALSO
mutt(1), mail(1), sendmail(8), netrc(5) or ftp(1)
2010-03