====== Howto send e-mails from command-line using msmtp ====== Some times, you may want to send an e-mail from the command line. If the host from which you are sending the e-mail does not have proper DNS configuration (reverse DNS too), the e-mail will not be sent. In these situations, what you can do is use a remote smtp server to send the e-mail. For this your e-mail client and MTA need to be configured to use the remote smtp server. This configuration depends on what MTA (Postfix, Sendmail, Exim, ..) and which e-mail client (mailx, mutt, mail ..) you are using The [[http://msmtp.sourceforge.net/|msmtp tool]] is an all-in-one e-mail client and MTA. The user can specify the smtp server among several other things in the command line. ===== Installing msmtp ===== Under Debian/Ububtu : apt-get install msmtp Under FreeBSD : pkg_add -vrf msmtp ===== Using msmtp ===== To send an e-mail through a remote smtp server: cat message | /usr/bin/msmtp --host=smtpserver.com -f from@example.fom to@example.com **Optional :** To create a secure ssh tunnel with the smtp server and transport the e-mail over the ssh tunnel. sudo ssh -N -l yourlogin -L 25:localhost:25 -L 143:localhost:143 smtpserver.com //Note that the above command also creates a tunnel for imap(143).// Now you can use msmtp as follows (localhost instead of smtpserver.com) cat message | /usr/bin/msmtp --host=localhost -f from@example.fom to@example.com {{tag>unix howto}} ~~DISCUSSION~~