# Ubuntu – How to change default FROM address for mail command using sSMTP

emailmailsmtpssmtp

I have installed:

• sudo apt-get install ssmtp
• sudo apt-get install mailutils

When I use command:

echo "something" | mail -s "testing email" email@example.com


The generated email have From field set to something like this:

From: "Username" <username@local.domain.internal>


Is there a config file or something, where I can change this FROM default address?

Note, that changing the TO field is easy, as explained here: How to get ssmtp to map local user to email address for the To: field, but I need to change the default FROM field.

Edit: I also need to change FROM address for sendmail emulation. In my case, the Cron sets FROM: root and TO: root, that I would like to change to normal email address.

There are a couple of settings in ssmtp that can be manipulated to allow a change in the 'From' field of emails:

1. There is a setting within /etc/ssmtp/ssmtp.conf. By default the system selects the 'From' address but this can be altered by unchecking the FromLineOverride line:

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
#FromLineOverride=YES


By 'unchecking' I mean remove the hash mark at the beginning of that particular line.

2. There can be settings within /etc/ssmtp/revaliases to allow a specific 'From' line from each user. The example given in revaliases is reasonably unhelpful:

# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.


But the man pages gives a much more explicit example:

A reverse  alias  gives  the From: address placed on a user's outgoing
messages and (optionally) the  mailhub  these  messages  will  be  sent
through. Example:

root:jdoe@isp.com:mail.isp.com

Messages  root  sends  will be identified as from jdoe@isp.com and sent
through mail.isp.com.


I personally do not use ssmtp instead I use msmtp where the syntax for altering the 'From' field is a lot simpler and can be contained in the file \$HOME/.msmtprc:

from my.email.address@myisp.com


which is a lot easier...

References: