Sending Email from Linux

 

Here is the simple way to write an email script which can be utilized to send emails to recipients.

Login to your Linux box , I am using a virtual machine with Linux Mint operating system installed running on Oracle Virtual Box.

login as: sloba
sloba@**********'s password:
Welcome to Linux Mint 17.2 Rafaela (GNU/Linux 3.16.0-38-generic i686)

Welcome to Linux Mint
 * Documentation:  http://www.linuxmint.com
Last login: Fri Jul 24 12:52:24 2015 from msi-l1028.metricstream.com
sloba@sloba-VirtualBox ~ $ 

Below is a very basic and simple script which can be used to send email :

 

##################################################################
# Email notification
##################################################################
SUBJECT="TEST EMAIL FROM UNIX"
# use form to send from whom the email address has sent
FROM="automail@slobaexpert.wordpress.com"
DESCRIPTION="THIS IS AN AUTO-GENERATED MESSAGE"
#Put the email address of the person to whom you want to send with comma seperator
EMAIL="<<to email address>> @<<hostname >>.com"
EMAILMESSAGE=/tmp/emailmessage

 echo "From: $FROM" > $EMAILMESSAGE
 echo "To: $EMAIL" >> $EMAILMESSAGE
 echo "Subject: $SUBJECT " >> $EMAILMESSAGE
 echo "************************************************************************" >> $EMAILMESSAGE
 echo "$DESCRIPTION : DO NOT REPLY TO THIS EMAIL MESSAGE. " >> $EMAILMESSAGE
 echo "************************************************************************" >> $EMAILMESSAGE
 echo " " >> $EMAILMESSAGE
 echo " " >> $EMAILMESSAGE
 echo "Test file email " >> $EMAILMESSAGE
 echo " " >> $EMAILMESSAGE
 echo " " >> $EMAILMESSAGE
 echo "Thanks, " >> $EMAILMESSAGE
 echo "$FROM" >> $EMAILMESSAGE
 cat $EMAILMESSAGE | /usr/sbin/sendmail -t

 

You can change the TO address from the above script and test it. But we need to make sure “sendmail ” is already installed on your server to use this , if not then you can install using the below command.

sudo apt-get install sendmail
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s