LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-28-2006, 10:56 PM   #1
manu82
LQ Newbie
 
Registered: Dec 2005
Posts: 12

Rep: Reputation: 0
Sending a mail


Hi ALL
could anybody please tell me how can i send a mail using cron
actually i want to send a mail using cron for confirmation
please anybody can send the code for this
Regards
bhushan
 
Old 03-01-2006, 05:06 AM   #2
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
The command to send mail is:

mail -s "Email subject in here" someone@somewhere.com < /dev/null


To get cron to send the mail you can create a script and place it in either:

/etc/cron.daily
/etc/cron.hourly
/etc/cron.weekly
/etc/cron.monthly

Or if you have a /etc/crontab file place and entry like this:

0 0 * * * root mail -s "Email subject in here" someone@somewhere.com < /dev/null
 
Old 03-01-2006, 06:28 AM   #3
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Actually, you can also just make the cron job print some stuff. It'll get mailed (probably to root user) automatically. But that just doesn't have all the flexibility you probably need.
ie put MAILTO=some_mail_address at the top of your crontab file. All stdout and stderr messages will be mailed to that address automatically (if you have a running mail server like sendmail/postfix/etc).

Another alternative to mail, is nail. But you'll need to download and install it first. /bin/mail is pre-installed on most Linux systems. Nice feature about nail is that it supports using SMTP directly to a mail server on your network. mail requires that you have your own mail server (actually MTA is a better term) (sendmail, etc) running.

Finally, if you do have sendmail, you can use sendmail's command line options to send mails out.
I believe you'll need the -t and -i options, but I've forgotten the exact command syntax.
"man sendmail" is your friend for this one...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Postfix mail transfer agent not sending mail locally or to other servers sketelsen Linux - Software 3 02-09-2006 11:16 AM
Cron mail sending using outside SMTP mail server Utah Linux - Software 6 08-24-2005 07:44 PM
Sending mail through mail server. TheRealDeal Linux - Networking 17 09-11-2004 11:31 PM
Mail Server not sending mail baye Linux - Software 1 05-28-2004 08:41 AM
Sending an automatic mail using bash + mail Minuteman Linux - Software 4 08-21-2003 12:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration