I’m sharing two code snippets that will send an email. These snippets accept three parameters: a subject, an email address and a text file containing the email message.
[topads][/topads]
Version 1:
#!/bin/bash ############################# # Snippet that send an email ############################# sendMail() { SUBJECT=$1 EMAIL=$2 EMAILMESSAGE=$3 /usr/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE }
Version 2:
#!/bin/bash ############################## # Snippet that send an email ############################## sendMail() { SUBJECT=$1 EMAIL=$2 EMAILMESSAGE=$3 cat $EMAILMESSAGE | /usr/bin/mail -s "$SUBJECT" $EMAIL }
My ‘mail’ tool is located ‘/usr/bin/mail’, but if yours is in a different location, change the path.
Hope this was helpful to you…
Share this article 🙂
[bottomads][/bottomads]
[…] In above code 'sendMail' is a function in 'sendMail.sh' that accepts three arguments: subject, email, and a text file for the email message. You can view the snippet here: send email snippet […]
RT @jgezau: How to #SendEmail – #Unix #Shell #Snippet #Linux http://t.co/3dHTBFJr