Gentoo Wiki




msmtp is an SMTP client. In the default mode, it transmits a mail to an SMTP server (for example at a free mail provider) which does the delivery. To use this program with your mail user agent (MUA), create a configuration file with your mail account(s) and tell your MUA to call msmtp instead of /usr/sbin/sendmail. Another advantage of msmtp is, that it seems to be very portable; It can be even used on alternative architectures such as AMD64.


Features include:


msmtp is available in portage. You should enable the USE flag ssl if you want to connect to SSL encrypted servers such as Gmail. Other USE flags that might be interesting for you are: gnutls and sasl. Now you can emerge msmtp using emerge -av msmtp.


Now you need to create a .msmtprc which contains all your SMTP accounts. Here is an example:

File: .msmtprc
# Set default values for all following accounts
logfile ~/.msmtp.log
syslog off

account default
user <username>
password <password>

The auth [<method>] can be added. It is not recommended to define an auth type yourself, but instead to just set auth with no arguments and let msmtp choose the best one. However, if you must, see man msmtp for available arguments.

You should also set the file rights of .msmtprc to a secure value as it contains sensitive information. Setting chmod 600 .msmtprc allows only you to access this file.


You can use the option logfile to change the path of your log file. 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. If the filename is a dash (-), msmtp prints the log line to the standard output. msmtp uses the faciality which can be set using the option syslog. This will log all entries with the chosen facility. Add this line, if you want to log these messages to /var/log/maillog.

File: .msmtprc
syslog LOG_MAIL

By default, msmtp's default faciality is LOG_USER. You can turn off logging completely by adding syslog off.


If your SMTP server supports TLS encryption, enable it by adding the tls line:

File: .msmtprc

msmtp will refuse to send your mail if you have tls in your ~/.msmtprc and your SMTP server has a TLS certificate that you do not trust. To get around this, either trust the certificate, or you can add tls_nocertcheck to your ~/.msmtprc.

Inherit values

This can be useful if you have more than one mail address on the same provider so that you can inherit all values of the other account and simply overwrite the "from" variable.

File: .msmtprc
account account2 : account1
from user@host.tld

Multiple accounts

msmtp supports multiple accounts. Set account <name> in your ~/.msmtprc and then you can use msmtp -a <name>.

Set a default account

If you do not want to specify the account you want to use in the msmtp command, you can set a default one.

File: .msmtprc
account default : <account-name>



This uses TLS authentication.

File: .msmtprc
account gmx
from <e-mail>
protocol smtp
port 465
user <e-mail>
password <password>
auth cram-md5
tls on
tls_starttls off
tls_certcheck on


File: .msmtprc
account gmail
from <e-mail>
protocol smtp
port 587
user <e-mail>
password <password>
auth on
tls on


You can send mails using the command line: msmtp recipient@host.tld < message. To use another account than the default one, specify -a: msmtp -a account recipient@host.tld < message

File: message
Subject: Test
This is the body


If msmtp is unable to send mails, check the output of msmtp -S -a <account name> and check the variables. This prints information about the SMTP server. This includes information about supported features (mail sizelimit, authentication, TLS, DSN, ...) and about the TLS certificate (if TLS is active).

See also

Retrieved from ""

Last modified: Tue, 07 Oct 2008 16:59:00 +0000 Hits: 960