LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Sending a mail (https://www.linuxquestions.org/questions/linux-software-2/sending-a-mail-420490/)

manu82 02-28-2006 10:56 PM

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

fotoguy 03-01-2006 05:06 AM

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

timmeke 03-01-2006 06:28 AM

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...


All times are GMT -5. The time now is 02:26 PM.