Can I set up system mail to use an external SMTP server?

  • Is it possible to set up system mail on a linux box to be sent via a different smtp server - maybe even with authentication? If so, how do I do this?

    If that's unclear, let give an example. If I'm at the command line and type:

    cat body.txt | mail -s "just a test" [email protected]
    

    is it possible to have that be sent via an external SMTP server, like G-mail ?

    I'm not looking for "a way to send mail from gmail from the command line" but rather an option to configure the entire system to use a specific SMTP server, or possibly one account on an SMTP server (maybe overriding the from address).

    It's the way most machines used to be set up, in fact. Do you have any particular MTA in mind? If not (this includes “what is an MTA?”), what distribution are you running?

    I'm on Ubuntu 10.04, found this article on setting up ssmtp, seems like it might work. can you elaborate more on how most machines are set up?

  • I found sSMTP very simple to use.

    In Debian based systems:

    apt-get install ssmtp
    

    Then edit the configuration file in /etc/ssmtp/ssmtp.conf

    A sample configuration to use your gmail for sending e-mails:

    # root is the person who gets all mail for userids < 1000
    [email protected]
    
    # Here is the gmail configuration (or change it to your private smtp server)
    mailhub=smtp.gmail.com:587
    [email protected]
    AuthPass=yourGmailPass
    UseTLS=YES
    UseSTARTTLS=YES
    

    Note: Make sure the "mail" command is present in your system. mailutils package should provide this one in Debian based systems.

    Update: There are people (and bug reports for different Linux distributions) reporting that sSMTP will not accept passwords with a 'space' or '#' character. If sSMTP is not working for you, this may be the case.

    as a note to others you may have to install ssmtp and then mailutils. i think mailutils sets up the mail command and symlinks to ssmtp so you can use the regular `mail` syntax :)

    @cwd Just tested on Ubuntu 13.04. I didn't have to install `mailutils` package (and it's not installed automaticaly). `ssmtp` worked out-of-the box.

    I just successfully used this in Debian on a BeagleBone Black and did have to install mailutils first.

    On Kubuntu 14.04, had to install *mailutils* after ssmtp. However it worked at first try.

    ssmtp does NOT verify the SSL/TLS certificate of the remote server on the current debian, ubuntu and redhat releases and also does NOT verify the hostname of the certificate. This is a major issue, as this effectively renders the encryption useless and your password is being transmitted alike to being plaintext and anyone can sniff it. ssmtp has had no active development since atleast 2009. So, if you care about the security of the email account you use for your servers outgoing emails, do NOT use ssmtp, but postfix (or something else) instead: unix.stackexchange.com/a/118101/72087

    Can you please provide some more details about your claims that sSMTP is not under active development anymore, as well as the security issue? Some link where it is discussed further maybe?

    I had to activate `FromLineOverride=YES` in order to send mails successfully

    @VangelisTasoulas That is already linked to from the discussion. You could try to do the minimal work yourself next time. Following the links I found the Debian GIT repo for SSMTP. It has seen no active development for the last decade: https://anonscm.debian.org/gitweb/?p=ssmtp/ssmtp.git

    @oligofren very kind of you to try to do the minimal work for me and failing to provide any value to this discussion. sSMTP is unmaintained with regards to adding new features, but that doesn't make a program useless as long as there are proper security updates in place. Debian and Red Hat take security very seriously and patch outstanding issues. Is there any outstanding security issue that hasn't been patched yet? If yes, please point me to it and do not be arrogant. And BTW, the latest version of SSMTP has been shipped in 2014. Someone probably forgot to push their changes in the git repo.

    @VangelisTasoulas You are right, I was a bit condescending. Sorry for that.

    There seems there is some activity here: https://salsa.debian.org/debian/ssmtp/commits/master. So while it may not be an active development, the package doesn't look abandoned either.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM