Sunday, April 13, 2014

Emailing from Bash CLI or script on ubuntu

Basically what you might be looking for is a command line or shell script email sender that knows how to work with gmail. If you are, search no more!

$ sudo apt-get install msmtp openssl ca-certificates
$ vim ~/.msmtprc
account default
host smtp.gmail.com
port 587
from GMAIL_ACCOUNT
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
auth on
user GMAIL_ACCOUNT
password GMAIL_PASSWORD
logfile ~/.msmtp
$ chmod 600  ~/.msmtp

Prepare a file starting wit:
to: DESTINATION
from: SENDER
subject: SUBJECT

And finally:
msmtp -t < YOUR_FILE

No comments:

Post a Comment