You are here: Home Linux Shell/Bash Programmierung MyScripts Send E-Mail from the shell with a script
Search
Advanced Search…
E-Mail

Webmail: webmail.wyden.com

E-Mail Preferences: postfix.wyden.com/users

E-Mail Administration: postfix.wyden.com

Statistics
Total: 473
Total Pages: 286
Total Folders: 87
Total Files: 18
Total Links: 26
Last modification: 19.04.2012 15:21
 

Send E-Mail from the shell with a script

by Wyden Silvan last modified 24.12.2009 12:34

#!/bin/bash
# Purpose: To send mails using the sendmail command
# Usage: SendMail
# Owner: Ketan Joshi
# Setting: Just change the variables at the start of the script to
#          appropriate values. Create a message by modifying the string BODY
#          You can even have html tags in the body.
# Limitation: Currently, this does not support attachments.
#——————————————————————–
#Temporary file for containing the mail message
tmp=/tmp/mail-body-`date +%F`;
touch $tmp && chmod 600 $tmp;
#Set up the various headers for sendmail to use
TO="it@mydomain.com";
CC="";
FROM="root@mydomain.com";
SUBJECT="Test Mail";
MIMEVersion="1.0";
CONTENTType="text/html; charset=utf-8";
#Here write the content of your mail.
BODY="
<b>Hello from ketan.</b>
This is test mail.
";

echo Sending the mail.
echo -e "To: $TO" > $tmp;
echo -e "Cc: $CC" >> $tmp;
echo -e "From: $FROM" >> $tmp;
echo -e "Content-Type: $CONTENTType">>$tmp;
echo -e "MIME-Version: $MIMEVersion">>$tmp;
echo -e "Subject: $SUBJECT">>$tmp;
echo -e "Body: $BODY">>$tmp;

/usr/sbin/sendmail -t < $tmp;

rm -rf $tmp;