GOAL: Get a text file on my file server into my gmail inbox.
The file server is running Ubuntu Server 8.04 I currently SSH into it from time to time and to check logs, SMART stats for hard drives, and such. I'm looking into setting up a scheduled script that runs some commands and sends me the output via email.
The only issue I'm having is with actually getting the email sent. I have no experience with email config under linux and all guides pointing to sendmail seem to assume lots of things on behalf of myself and my current config. The servers are set up for file sharing with samba and NOT as mail, web, or dns servers. I don't want to run a mail server or route anything from the server or receive any mail on (or with) the server, unless any of that helps me accomplish the goal. The file server is on our normal network and has internet access.
I own several website domains (and have a hosting package). I've been able to set up apps like thunderbird to send mail using one of the accounts from my website by filling in smtp.mydotcom.com for the outgoing server to use and changing ports etc to match the information from my website's cpanel config page. Is there a way to do something similar so I can send an email from my file server to my external email?
EDIT: Here are the steps I took after reading Dennis Williamson's answer below. I was up and running in only a few minutes!
Install esmtp:
sudo apt-get install esmtp
I created a new email account on my website (called "alerts") and edited /etc/esmtprc like this:
hostname=mail.mydomain.com:26
username=alerts+mydomain.com
(These values were provided by the cpanel admin page)
Then I created a file called "eheader" with the default top of email:
To: Me <[email protected]>
From: Alerts <[email protected]>
Subject: subjectMessage Body
So, in order to fire off the mail the following command can be used:
cat eheader <file1> <file2> ... <fileN> | /usr/bin/esmtp -t
So it's easy to vary which files are sent for the daily/weekly/etc jobs.
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:
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.
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.
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:
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):
See
man crontab
andman cron
ANOTHER UPDATE:
You can send email from the commandline with SendEmail
You want to send mail, but not configure a mail server. Not a tough order but strange. Postfix can be set up to send out email in a few seconds, and it would often be useful to get normal emails sent to root, such as notices of MD raid components in failure.
If you cannot or will not set up email on that system, what do we have left?
If one of your servers or web hosting sites does have ssh, and probably has mail services already configured, how about a cron which scp's the log files from the server and mails it from the system having mail? Mail is often sent from unix with the mail or mailx command.
Prior to this you could put the stuff you want reported in that file with whatever scripts or cp commands you would need to do. If it works better, you could place the cron on the Ubuntu server and have it issue ssh commands to the second server to pull the data down and mail it.
I use a perl script with Mail::Sendmail to email reports from my servers (and Net::Twitter for status updates). Of course, that means dealing with CPAN which may not be worth it as you have to
make
the packages.Try this. It will work on most Linux distributions out of box.
Try mutt. It is a very versatile. Allows command line usage incuding the ability to send attachments. Mutt is installed in Ubuntu server by default. So you should have it. The typical command line look like:
See 'man mutt' for full usage options. It also has an interactive mode if you just enter 'mutt' in a terminal.