-
-
Save nestorwheelock/df9223e164ee58d39010f697da4f17b7 to your computer and use it in GitHub Desktop.
How to send an email from bash via SMTP Auth
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
$!/bin/sh | |
# Send an email from bash with SMTP This is an attempt to create a pseudo class to have an email routine/template to use | |
# in scripts that send emails. I'm using FreeBSD so the original gist had been modified to make it work there. | |
RECIPIENT="" | |
SENDERNAME="" | |
SENDEREMAIL="" | |
SMTPUSERNAME="" | |
SMTPPASSWD="" | |
SMTPSERVER="" | |
SUBJECT="" | |
BODY=`cat <<'EOF' | |
Insert Body Here | |
EOF` | |
# Use quotes around "$BODY" to preserve newlines | |
# This seems to be working on FreeBSD | |
$SENDMAIL=`echo "$BODY" | mailx -s $SUBJECT $RECIPIENT -f "From: $SENDERNAME <$SENDEREMAIL>" | |
$SENDMAIL | |
# not working on FreeBSD -S not found so might make a switch to mutt | |
#SENDEMAIL=`echo "$BODY" | mailx -s $SUBJECT -S smtp=smtp://$SMTPSERVER -S smtp-auth=login -S smtp-auth-user=$SMTPUSERNAME -S smtp-auth-password=$SMTPPASSWD -S from="$SENDERNAME <$SENDEREMAIL>" $RECIPIENT)` | |
$SENDEMAIL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment