Thursday, September 21, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  1] [ 0]  / answers: 1 / hits: 5896  / 8 Months ago, sun, february 5, 2023, 7:11:58

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.

More From » 12.04


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 the mailx command, for example:

echo "Mail." | mailx -s "Subject" [email protected]

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 is firas and the hostname is nomo:

firas@nomo ~ % whoami
firas@nomo ~ % hostname -f

So when I send an email with the above command, the sender address will be firas@nomo, as can be seen from mail.log:

firas@nomo ~ % tail -n 3 /var/log/mail.log
Jun 9 20:37:46 nomo sSMTP[2203]: Creating SSL connection to host
Jun 9 20:37:48 nomo sSMTP[2203]: SSL connection using RSA_AES_128_CBC_SHA1
Jun 9 20:37:50 nomo sSMTP[2203]: Sent mail for firas@nomo (221 2.0.0 closing connection) uid=1000 username=firas outbytes=364

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 in ssmtp.conf which lets one specify an arbitrary domain, which sSMTP will use when sending mail. Namely, this is the rewritedomain option, so if I have this in my ssmtp.conf:

then the sender address will be [email protected].

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 of ssmtp.conf to YES, and then use the -a option of mailx:

echo "Mail." | mailx -s "Subject" -a 'From: [email protected]' [email protected]

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.

[#24798] Monday, February 6, 2023, 8 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 439
Total Questions: 99
Total Answers: 131

Location: Vanuatu
Member since Wed, Oct 14, 2020
3 Years ago
ettorina questions
Thu, Sep 1, 22, 15:28, 1 Year ago
Mon, Mar 14, 22, 06:04, 2 Years ago
Sun, Jul 24, 22, 13:31, 1 Year ago