Created
June 30, 2016 17:50
-
-
Save ppdeassis/badd934991b7939f088274bfeebb613d to your computer and use it in GitHub Desktop.
Setting up mailx to send mail from command line using external server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ref: https://coderwall.com/p/ez1x2w/send-mail-like-a-boss | |
# install mailx | |
yum -y install mailx | |
# create a directory with a certificate, to send mail using TLS | |
mkdir ~/.certs | |
certutil -N -d ~/.cert | |
# create a user ~/.mailrc, to use custom settings | |
cat <<EOT >> .mailrc | |
# external smtp server | |
set smtp-use-starttls | |
set ssl-verify=ignore | |
set nss-config-dir=/home/user/.certs | |
set smtp="smtp://mail.smtp.server:port" # smtp://smtp.gmail.com:587, smtp://mail.company.net:25 | |
set smtp-auth=login | |
set smtp-auth-user="[email protected]" | |
set smtp-auth-password="S3cr37" | |
set from="[email protected](My Name)" | |
EOT | |
# now send mail as you wish: | |
# NOTE: you may need to enclose mail addresses in <>, depending on server config. | |
# - <[email protected]> | |
# simple message | |
echo "Your message" | mail -s "Message Subject" email@address | |
# with attachment | |
echo "Message" | mail -s "Subject" -a /loc/to/attachment.txt email@address | |
# A weekly report | |
git report | mailx -A gmail -s "Last Week Activity Report" [email protected] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment