12

I have installed:

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

When I use command:

echo "something" | mail -s "testing email" [email protected]

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

From: "Username" <[email protected]>

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.

6
  • 1
    Possible duplicate of How to get ssmtp to map local user to email address for the To: field
    – andrew.46
    Feb 10, 2016 at 11:16
  • @andrew.46 - no it is not duplicate. I have already searched, and could not find the answer. And edited the question.
    – Maris B.
    Feb 10, 2016 at 13:08
  • My apologies! My best advice would be to move to msmtp which makes changing the From field quite easy. If this is is not possible have you looked at the 'Reverse Alias' settings of ssmtp? I would be happy to write this up as a proper answer if this sends you on the right track... Config files are /etc/ssmtp/ssmtp.conf, /etc/ssmtp/revaliases and /etc/aliases.
    – andrew.46
    Feb 10, 2016 at 22:04
  • @andrew.46, thanks for the comment. I have tried with revaliases, and it rewrites FROM address if using mail command, but it does not if using sendmail emulation. Also tried msmtp, but it seems, that it only adds FROM address if it is missing. It never overwrites.
    – Maris B.
    Feb 13, 2016 at 17:00
  • @andrew.46, updated question with sendmail requirement. But it seems that I am doing this wrong. Everyone is using Exim or Postfix. So it seems, that I need to switch to one of them and delete this question...
    – Maris B.
    Feb 13, 2016 at 17:13

1 Answer 1

13

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:[email protected]: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:[email protected]:mail.isp.com
    
    Messages  root  sends  will be identified as from [email protected] 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 [email protected]

which is a lot easier...

References:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .