标签归档:msmtp

how to send mail from linux CMD line via gmail

http://tuxtweaks.com/2012/10/send-gmail-from-the-linux-command-line/

Install msmtp

The first step is to install the msmtp-mta package.
sudo apt-get install msmtp-mta
After the install is complete you’ll need to set up the defaults file with your Gmail account information. You need to create a file in your home directory called .msmtprc.
nano ~/.msmtprc
Paste the following into the file and edit the portions in bold to reflect your account information.

#Gmail account
defaults
logfile ~/msmtp.log
account gmail
auth on
host smtp.gmail.com
from your_address@gmail.com
auth on
tls on
tls_trust_file /usr/share/ca-certificates/mozilla/Equifax_Secure_CA.crt
user your_address@gmail.com
password your_gmail_password
port 587
account default : gmail
Save the file and exit the text editor. Since this file contains your account credentials, you’ll want to change the permissions to make the file readable only by you.
chmod 600 .msmtprc
Install mailx

Now that your computer is configured to talk to Gmail, you need a command line email program to handle writing your email. For this I’m going to use mailx from the heirloom-mailx package.
sudo apt-get install heirloom-mailx
Now you need to set up the defaults file so that mailx uses msmtp to send out the email. This file is called .mailrc.
nano ~/.mailrc
Now paste the following into the file and save it.
set sendmail=”/usr/bin/msmtp”
set message-sendmail-extra-arguments=”-a gmail”
You should now be able to send email from your terminal command line.
Sending email from the command line

Now you can send email from the command line like this:
mail -s “Subject” address@example.com

#######################Equifax_Secure_CA.crt

—–BEGIN CERTIFICATE—–
MIIDIDCCAomgAwIBAgIENd70zzANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQG
EwJVUzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UECxMkRXF1aWZheCBTZWN1
cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MB4XDTk4MDgyMjE2NDE1MVoXDTE4
MDgyMjE2NDE1MVowTjELMAkGA1UEBhMCVVMxEDAOBgNVBAoTB0VxdWlmYXgx
LTArBgNVBAsTJEVxdWlmYXggU2VjdXJlIENlcnRpZmljYXRlIEF1dGhvcml0
eTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwV2xWGcIYu6gmi0fCG2R
FGiYCh7+2gRvE4Ri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