Skip to content

Instantly share code, notes, and snippets.

@ppdeassis
Created June 30, 2016 17:50
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ppdeassis/badd934991b7939f088274bfeebb613d to your computer and use it in GitHub Desktop.
Save ppdeassis/badd934991b7939f088274bfeebb613d to your computer and use it in GitHub Desktop.
Setting up mailx to send mail from command line using external server
# 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="user@domain.ltd"
set smtp-auth-password="S3cr37"
set from="whoami@server.com(My Name)"
EOT
# now send mail as you wish:
# NOTE: you may need to enclose mail addresses in <>, depending on server config.
# - <mail@address.com>
# 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" client@company.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment