I feel like my problem is very simple, but I've been trying for quite some time and haven't cracked it. You experienced server guys will probably laugh at this, but I'm finally at the point I need help or I'll never get anywhere.
I have a little box running 12.04 LTS and I've wanted to script some status checks and have the server send me an email and schedule this with cron.
I basically want a command line mail client that I can set up as easily as Thunderbird to send through my existing SMTP through the command line. Something that can easily be rolled into my bash scripts.
I already have a remote host handling our email, SMTP, MTA, all that garbage. I don't particularly want to set up a relay just to send email when I have one that everyone else in the company already uses. I've tried, but there are too many aspects I don't understand AND I don't see why I should set up something local when we already pay for a remote host to do these things.
If I absolutely have to set up sendmail or postfix, then so be it, but I'd appreciate a simple alternative. I'm open to practically anything at this point.
Best Answer
If you mean that you are sending e-mail through a third-party SMTP server (provided by your ISP, for example), then you can install
ssmtp
, which is a drop-in replacement for Postfix/Sendmail but specialised to that precise task of sending mail through a remote SMTP, and is thus much easier to configure. Then you can send e-mail with themailx
command, for example:EDIT: E-mail is a very complicated business... Some things to keep in mind:
Note that the command above does not specify a sender address (i.e., the addres that the recipient will see in the "From" field of his e-mail client). By default, the sender address is your login name on your local machine, followed by
@
, followed by the full hostname of the local machine. For example on my machine, the login name isfiras
and the hostname isnomo
:So when I send an email with the above command, the sender address will be
firas@nomo
, as can be seen frommail.log
:The vast majority of servers will refuse to relay this e-mail (as an anti-spam measure), because the domain name
nomo
is not a valid domain. Fortunately, there is an option inssmtp.conf
which lets one specify an arbitrary domain, whichsSMTP
will use when sending mail. Namely, this is therewritedomain
option, so if I have this in myssmtp.conf
:then the sender address will be
firas@fkraiem.org
.Normally, the above should be sufficient (that is, as long as your sender address has a valid domain, the server should relay your mail). However, some e-mail providers are extra zealous, and will only permit you to use the e-mail address you have registered with them. This means that in addition to changing the domain name as above, you might need to either change your login name on the local machine, or register a new address with your provider (if they allow it), so that the final address will match your registered address.
Another way to specify an arbitrary sender address is to set the
fromlineoverride
option ofssmtp.conf
toYES
, and then use the-a
option ofmailx
:This is however non-standard, and might not work on OSes other than Ubuntu (and other GNU-based systems). One may also use other, more sophisticated clients, such as
mutt
.