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.

  • 1
  • @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 '16 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 '16 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 '16 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 '16 at 17: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

    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:
    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...


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.