https://wiki.archlinux.org/api.php?action=feedcontributions&user=Fdservices&feedformat=atomArchWiki - User contributions [en]2024-03-28T20:09:10ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Msmtp&diff=247141Msmtp2013-02-12T17:10:46Z<p>Fdservices: /* Using the mail command */</p>
<hr />
<div>[[Category:Email Client]]<br />
[[Category:Mail Server]]<br />
{{Lowercase title}}<br />
<br />
{{Article summary start}}<br />
{{Article summary text|msmtp configuration and usage hints.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|msmtp|http://msmtp.sourceforge.net/}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|mutt}}<br />
{{Article summary wiki|OfflineIMAP}}<br />
{{Article summary end}}<br />
<br />
'''msmtp''' is a very simple and easy to use smtp client with excellent [[Wikipedia:sendmail|sendmail]] compatibility.<br />
<br />
An alternative lightweight MTA that also handles local mail is {{AUR|dma}}, available in the [[AUR]].<br />
<br />
==Installing==<br />
msmtp can be [[pacman|installed]] with package {{Pkg|msmtp}}, available in the [[official repositories]]. Optionally, installing {{Pkg|msmtp-mta}} creates a sendmail alias to msmtp.<br />
<br />
==Quick start==<br />
The following is an example of a msmtp configuration file for several accounts. If msmtp throws errors when using this file, search for double byte '\xc2\xa0' characters that may have been erroneously inserted.<br />
{{hc|~/.msmtprc|<br />
# Accounts will inherit settings from this section<br />
defaults<br />
auth on<br />
tls on<br />
tls_trust_file /usr/share/ca-certificates/mozilla/Thawte_Premium_Server_CA.crt<br />
<br />
# A first gmail address<br />
account gmail<br />
host smtp.gmail.com<br />
port 587<br />
from username@gmail.com<br />
user username@gmail.com<br />
password password<br />
tls_trust_file /etc/ssl/certs/ca-certificates.crt<br />
<br />
# A second gmail address<br />
account gmail2 : gmail<br />
from username2@gmail.com<br />
user username2@gmail.com<br />
password password2<br />
<br />
# A freemail service<br />
account freemail<br />
host smtp.freemail.example<br />
from joe_smith@freemail.example<br />
user joe.smith<br />
password secret<br />
<br />
# A provider's service<br />
account provider<br />
host smtp.provider.example<br />
<br />
# Set a default account<br />
account default : gmail<br />
}}<br />
<br />
msmtp will refuse to start if ''user'' configuration file is readable and writeable to anyone else but the owner:<br />
$ chmod 600 ~/.msmtprc<br />
<br />
This does not apply to system configuration file (in Arch, this is /etc/msmtprc; copy the example over from /usr/share/doc/msmtp/ ).<br />
<br />
==Using the mail command==<br />
To send mails using the 'mail' command you have to install {{Pkg|heirloom-mailx}} (some applications require it, e.g. smartd):<br />
<br />
$ pacman -S heirloom-mailx<br />
<br />
Either install {{Pkg|msmtp-mta}} or edit /etc/mail.rc to set sendmail<br />
{{hc|/etc/mail.rc|2=set sendmail=/usr/bin/msmtp}}<br />
<br />
You need to have a .msmtprc file in the home of every users who want to send mail (for example if you want to send mails as root), or alternatively you can use a system wide /etc/msmtprc<br />
<br />
msmtp also understands aliases. Add the following line to the defaults section of msmtprc or your local configuration file:<br />
{{hc|/etc/msmtprc|2=aliases /etc/aliases}}<br />
<br />
and create an aliases file in /etc<br />
{{hc|/etc/aliases|2=# Example aliases file<br />
<br />
# Send root to Joe and Jane<br />
root: joe_smith@example.com, jane_chang@example.com<br />
<br />
# Send cron to Mark<br />
cron: mark_jones@example.com<br />
<br />
# Send everything else to admin<br />
default: admin@domain.example}}<br />
<br />
==Test msmtp==<br />
The {{Ic|-a}} flag specifies the account to use as sender; {{Ic|<username>@domain.com}} is the recipient.<br />
<br />
Save (with the addresses you want to use)<br />
To: <username>@domain.com<br />
From: username@gmail.com<br />
Subject: A test<br />
<br />
Yadda, yadda, yadda.<br />
<br />
as, say, "test.mail".<br />
<br />
Then execute<br />
<br />
$ cat test.mail | msmtp -a default <username>@domain.com<br />
<br />
Do ''not'' merely use "echo 'Yadda, yadda, yadda.'" instead of "cat test.mail". This causes at least Gmail and Yahoo to deliver the mail incorrectly.<br />
<br />
==Configuring cron for msmtp==<br />
Assuming you're using the default cron daemon, {{Pkg|cronie}}, you'll want to make sure it knows to use msmtp rather than sendmail.<br />
<br />
You can do this by either installing {{Pkg|msmtp-mta}} or by adding the proper crond option in /etc/conf.d/crond:<br />
CRONDARGS=-m/usr/bin/msmtp<br />
<br />
==Miscellaneous==<br />
<br />
===Practical password management===<br />
The {{Ic|password}} directive may be omitted. In that case, if the account in question has {{Ic|auth}} set to a legitimate value other than {{Ic|off}}, invoking msmtp from an interactive shell will ask for the password before sending mail. msmtp will not prompt if it has been called by another type of application, such as [[Mutt]].<br />
There is a solution for such cases: the {{ic|--passwordeval}} parameter.<br />
You can call msmtp to use an external keyring tool like gpg:<br />
{{bc|msmtp --passwordeval 'gpg -d mypwfile.gpg'}}<br />
If gpg prompt for the passphrase cannot be issued (e.g. when called from Mutt) then start the gpg-agent before.<br />
<br />
If you cannot use a keyring tool for any reason, you may want to use the password directly. There is a patched version {{aur|msmtp-pwpatched}} in the AUR that provides the {{ic|--password}} parameter. Note that it is a '''huge security flaw''', since any user connected to you machine can see the parameter of any command (in the /proc filesystem for example).<br />
<br />
If this is not desired, an alternative is to place passwords in {{ic|~/.netrc}}, a file that can act as a common pool for msmtp, [[OfflineIMAP]], and associated tools.<br />
<br />
===Using msmtp offline===<br />
<br />
Although msmtp is great, it requires that you be online to use it. This isn't ideal for people on laptops with intermittent connections to the Internet or dialup users. Several scripts have been written to remedy this fact, collectively called msmtpqueue.<br />
<br />
The scripts are installed under {{ic|/usr/share/doc/msmtp/msmtpqueue}}. You might want to copy the scripts to a convenient location on your computer, ({{ic|/usr/local/bin}} is a good choice).<br />
<br />
Finally, change your MUA to use msmtp-enqueue.sh instead of msmtp when sending e-mail. By default, queued messages will be stored in {{ic|~/.msmtpqueue}}. To change this location, change the {{ic|QUEUEDIR&#61;$HOME/.msmtpqueue}} line in the scripts (or delete the line, and export the QUEUEDIR variable in {{ic|.bash_profile}} like so: {{ic|export QUEUEDIR&#61;"$XDG_DATA_HOME/msmtpqueue"}}). <br />
<br />
When you want to send any mail that you've created and queued up run:<br />
$ /usr/local/bin/msmtp-runqueue.sh<br />
<br />
Adding {{ic|/usr/local/bin}} to your PATH can save you some keystrokes if you're doing it manually. The README file that comes with the scripts has some handy information, reading it is recommended.<br />
<br />
===Vim syntax highlighting===<br />
The msmtp source distribution includes a {{ic|msmtprc}} highlighting script for [[Vim]]. Install it from {{ic|./scripts/vim/msmtp.vim}}.<br />
<br />
===Send mail with PHP using msmtp===<br />
Look for ''sendmail_path'' option in your {{ic|php.ini}} and edit like this:<br />
{{bc|1=<br />
sendmail_path = "/usr/bin/msmtp -C /path/to/your/config -t"<br />
}}<br />
<br />
Note that you '''can not''' use a user configuration file (ie: one under ~/) if you plan on using msmtp as a sendmail replacement with php or something similar.<br />
In that case just create /etc/msmtprc, and remove your user configuration (or not if you plan on using it for something else). Also make sure it's readable by whatever you're using it with (php, django, etc...)<br />
<br />
From the msmtp manual: ''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''<br />
<br />
So it's impossible to have a conf file under ~/ and have it still be readable by the php user.<br />
<br />
To test it place this file in your php enabled server or using php-cli.<br />
{{bc|<br />
<?php<br />
mail("your@email.com", "Test email from PHP", "msmtp as sendmail for PHP");<br />
?><br />
}}<br />
<br />
==Troubleshooting==<br />
===Issues with TLS===<br />
If you see the following message:<br />
msmtp: TLS certificate verification failed: the certificate hasn't got a known issuer<br />
it probably means your tls_trust_file is not right.<br />
<br />
Just follow the [http://msmtp.sourceforge.net/doc/msmtp.html#Transport-Layer-Security fine manual]. It explains you how to find out the server certificate issuer of a given smtp server. Then you can explore the {{ic|/usr/share/ca-certificates/}} directory to find out if by any chance, the certificate you need is there. If not, you will have to get the certificate on your own.<br />
<br />
If you are trying to send mail through GMail and are receiving this error, have a look at [http://www.mail-archive.com/msmtp-users@lists.sourceforge.net/msg00141.html this] thread or just use the second GMail example above.<br />
<br />
If you are completely desperate, but are 100% sure you are communicating with the right server, you can always temporarily disable the cert check:<br />
$ msmtp --tls-certcheck off</div>Fdservices