Configure mail on Ubuntu

2

How do I configure mail on my Ubuntu 14.04 to use with a bash file that requires mail function? I have not found any guides that I can use with Ubuntu 14.04

QuyNguyen2013

Posted 2014-07-29T01:03:33.013

Reputation: 499

There all no guides I can find for Desktop Ubuntu, not Ubuntu server. – QuyNguyen2013 – 2014-07-29T02:21:42.100

Answers

5

Traditionally, the mail command just pipes the generated message to /usr/sbin/sendmail, which is then expected to deal with SMTP, UUCP, Bitnet, or whatever else the recipient addresses describe. The most general solution, then, would be to install a package that provides the sendmail tool.

There are many choices here – you can use a full-featured MTA (postfix, exim4, opensmtpd…) or a simple forwarder (msmtp, ssmtp, esmtp…). Forwarders are only capable of sending the message to one specific server (e.g. Gmail's or other provider's), and usually are enough for this purpose. Full mail servers support both direct and indirect transfer.

(Note that if you want the message to have a From: ...@gmail.com, then you must forward it through Gmail servers. The same applies to most other providers. On the other hand, if you have your own domain name, you'll want a full mail server too.)

I cannot describe every single option here. If you install a forwarder, the configuration should be more or less self-explanatory. If you want to configure a full mail server to forward mail through a provider, search for terms "relay mail" or "smarthost". Specifically, many people have written tutorials to make Postfix/Sendmail/etc. relay all messages through Gmail. I'm using msmtp though, so here's an example ~/.msmtprc.

Whichever you choose, make sure that either /usr/sbin/sendmail or /usr/lib/sendmail invokes the right mail program.


There is also another option. Several versions of the mail command exist; one with a large number of features is called heirloom-mailx in Ubuntu repositories (later renamed to s-nail). Among other things it's capable of talking to your provider's SMTP servers directly, without a separate sendmail tool.

If you install heirloom-mailx, you can skip all of the above, and set the necessary SMTP variables in your ~/.mailrc; for example:

# ~/.msmtprc

defaults
    tls on
    tls_trust_file /etc/ssl/certs/ca-certificates.crt

account default
    from grawity@gmail.com
    host smtp.gmail.com
    port 587
    auth plain
    user grawity@gmail.com
    password ********
# ~/.mailrc

set smtp="grawity%40gmail.com@smtp.gmail.com:587"
set smtp-use-starttls
set smtp-auth="plain"

user1686

Posted 2014-07-29T01:03:33.013

Reputation: 283 655

How do I configure heirloom mailx with yahoo? – QuyNguyen2013 – 2014-08-01T14:00:07.580