Reputation: 13
I m new to bash scripting.
I have this command line to send an email with sstmp from the terminal:
{
echo To: [email protected]
echo From: [email protected]
echo Subject: "[Alert]"
echo 'McDonalds now offers vegan burgers and vegan ice cream!'
} | ssmtp [email protected]
I would like to execute this in a bash script. Can someone tell me how this is best done?
Thanks!
Upvotes: 0
Views: 3683
Reputation: 61
I've read other articles here on stackoverflow. The Control-D is actually the keystroke for end of file (EOF). I've written a bash script that sends using SSMTP. Give this a try:
SUBJECT="TEST TEST TEST"
CONTENTS="This is an email!"
/usr/sbin/ssmtp -t << EOF
To: [email protected]
From: [email protected]
Subject: $SUBJECT
$CONTENTS
Cheers,
Me
EOF
The -t in SSMTP parses the email and if it finds a valid To:, CC: or Bcc: then it uses those addresses. Just make certain you have your ssmtp config good to go before going this far. Likewise, your ssmtp executable may be located in a different place, adjust accordingly.
Upvotes: 6