I want to send automatic e-mail as a cron job from my Xubuntu 8.04 laptop. Originally, I tried routing it through the legacy mail spools - it is, after all, on the same laptop as my e-mail - but gave up in despair. Thanks to Ubuntu Forums for the info.
sudo apt-get install ssmtp heirloom-mailx
sudo mousepad /etc/ssmtp/ssmtp.confto edit the ssmtp config file. Modify or add the following lines to the config file:
mailhub=mail.mymailserver.com AuthUserfirstname.lastname@example.org AuthPass=my_mail_passwordThe nail config file does not need to be changed at all.
- Using the
nailcommand to send e-mail:
Tip: Pay close attention to the <RETURN>s and <CTRL+D>s
E-mail body text<CTRL+D>
nail email@example.com Subject: Lotta viruses coming into this account I need to stop responding to the spam.
- Generating e-mail as part of a script or
nail -s "Test 3" firstname.lastname@example.org < /tmp/test_emailwill send the following e-mail.
From: You (automatic) To: email@example.com Subject: Test 3 Message Body: (read from file /tmp/test_email)
nail -s "Test 3" firstname.lastname@example.org < /dev/nullwill send an e-mail with a blank body - good for quick reminders using the subject line only.
To generate e-mail from
cronevents, use the command
crontab -eto edit your crontab file:
26 21 * * * nail -s "Test 3" email@example.com < /tmp/test_email
This crontab entry will send the same "Test 3" e-mail every day at 9:26 p.m.
Many elements can be added or customized - this is simple enough to generate automatic e-mails to myself.
UPDATE: September 9, 2008: I could do this in evolution, but it's more fun to use cron and nail or zenity
This crontab entry:
0 6 28 * * /usr/bin/nail -s "Reminder bot: Pay The Store Rent!" firstname.lastname@example.org </dev/null
will send the following e-mail at 6:00 am on the 28th of each month,
From: me <my computer> To: email@example.com Subject: Reminder bot: Pay The Store Rent! Date: Thu, 28 Jul 2008 06:00:01 -0500 Text: NoneSo I won't forget to pay the rent.... It's important.
This sends an e-mail to a known (to nail) e-mail server, so all machines that check the account get the mail.
Alternately, if I want a a pop-up window:
0 6 28 * * DISPLAY=:0.0 /usr/bin/zenity --info --title "Reminder Bot" --text "Pay The Store Rent"
will give me a pop-up window instead, and
0 6 28 * * DISPLAY=:0.0 /usr/bin/zenity --notification --text "Reminder Bot: Pay The Store Rent"
will give me a tiny notification-area icon.