Receive email alerts from Linux file server
Solution 1:
I use esmtp
, which is a send-only MTA, for that purpose. It is very simple to set up. It has sendmail-compatible command-line options (some ignored). It's in the repositories.
Here is a simple example:
echo -e "To: Recipient Name <[email protected]>\n\
From: Me Myself and I <[email protected]>\n\
Subject: Here is the example I promised\n\n\
$(<somefile)" | /usr/bin/esmtp -t
This sends the contents of the file named "somefile".
There is a very simple configuration file, /etc/esmtprc
, that contains the hostname, username and password for your upstream email provider (I'm assuming yours is gmail).
Instructions for setting it up for Gmail are here.
Solution 2:
Look into ssmtp, which is a sendmail replacement that just passes on email to an SMTP server that you configure it with. It's probably one of the simplest ways you can get the capability to send emails programmatically. A web search for "ssmtp" should come up with plenty of tutorials and instructions on how to configure it.
Also, most programming/scripting languages have SMTP libraries available, so if you're familiar with, say, Perl or Python, you could write a little script that connects to an SMTP server to send the mail - basically you'd be writing your own, simpler version of ssmtp.
Solution 3:
What you need to do is setup a SMTP server on the Ubuntu box that is configured to forward to the real SMTP server (on your network or at your ISP) such as ssmtp or esmtp. Here's a list of lightweight ones (mutt docs):
http://wiki.mutt.org/?LightSMTPagents
Update:
Since you're running Ubuntu, you'll have Exim installed.
You can configure it with sudo dpkg-reconfigure exim4-config
. It's quite easy to setup to relay mail, once you read some of the docs.
/Update
The following are the Gmail SMTP server settings for sending mail through Gmail from any email client program:
- set Gmail SMTP server address: smtp.gmail.com
- Configure Gmail SMTP user name as: your full Gmail address (including @gmail.com) Google Apps users may have to enter username@your_domain.com
- Configure Gmail SMTP password as: Your Gmail password
- Configure Gmail SMTP port as: 465 or 587
- Configure Gmail SMTP TLS/SSL required as: yes
Finally, you will write a script that calls a command-line mail client like mutt (I don't believe mail or mailx do attachments). You could also use Perl's or Python's mail APIs. The script creates an email and attaches the files you want.
Finally you would put a crontab entry in for the script run daily (or whatever interval you want):
01 * * * * root echo "This command is run at one min past every hour"
17 8 * * * root echo "This command is run daily at 8:17 am"
17 20 * * * root echo "This command is run daily at 8:17 pm"
00 4 * * 0 root echo "This command is run at 4 am every Sunday"
* 4 * * Sun root echo "So is this"
42 4 1 * * root echo "This command is run 4:42 am every 1st of the month"
01 * 19 07 * root echo "This command is run hourly on the 19th of July"
See man crontab
and man cron
ANOTHER UPDATE:
You can send email from the commandline with SendEmail