954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using Shell Script how to send mail automatically

Hi all,
Problem: Send mail is configured in my system and now i want to write a shell script using which i can send mail to my rediffmail account.

Its little urgent & i will be very thankful if someone send me the code.
regards,
Sanjeev Kumar(sanju456@rediffmail.com)

sanju456
Newbie Poster
2 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

Hi,

You don't need to write shell script for this one. You can do it in command line itself.

echo "This is mail body" | mail -s "This is subject" [email]mail_ID@somedomain.com[/email]

Or

cat mail_body_file.txt | mail -s "This is subject" [email]mail_ID@somedomain.com[/email]

Durai
Newbie Poster
3 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

how to send autometic mail usins Linux shell script

shankha_achar
Newbie Poster
1 post since Apr 2008
Reputation Points: 10
Solved Threads: 0
 

You have already been told - just use the mail command to do what you want to do, nested in the logic you want it done for.

For instance, the following will check to see if a file exists every 3 minutes. If the file exists, it will e-mail the contents of the file to [email]mail_ID@somedomain.com[/email] and then move the file to another location (so that the same file is not sent again).

while [1]
do
 if [ -f /path/to/file ]
 then
    cat /path/to/file | mail -s "This is subject" mail_ID@somedomain.com
    mv /path/to/file /path/to/somewhere/else
 fi
sleep 180
done


[I believe]You will need to have an e-mail server installed on the machine. Otherwise, there is a perl script out there called "sendemail.pl" that you can probably google - this script will allow you to bounce the email off a relay server - an actual SMTP server such as exchange.

... Just now realizing how old the original request is - too much typing to turn back now.

omrsafetyo
Junior Poster in Training
58 posts since Apr 2008
Reputation Points: 13
Solved Threads: 9
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You