0

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!

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.