1

I have set up mailutils in ubuntu 20.04, I can send an email using the command below

echo 'this is a body' | mail -s 'Test Email' -r noreply@domain.com myaddress@example.com

but the first problem with the above command is that it sends the mail with the name 'Ubuntu', which is my current user, only the sender name is not good in this case, the sender address is the one I specified. (Ubuntu <noreply@domain.com>).

Then in this second command when I try to send specifying the sender's name:

echo 'this is a body' | mail -s 'Test Email' -r 'SenderName <noreply@domain.net>' myaddress@example.com

In my email inbox it will show the following sender: Ubuntu <SenderName@mainmailserver-1-eu>

How can I change the sender name in mailutils while preserving the sender address?

tripleee
  • 175,061
  • 34
  • 275
  • 318
YaRmgl
  • 356
  • 1
  • 6
  • 19

2 Answers2

2

The -r option sets the envelope sender. Probably try

mailx -s 'Test Email' -a 'From: SenderName <noreply@domain.net>' myaddress@example.com <<<"this is a body"

You may wish to also separately set the envelope sender, but this adds a proper From: header which controls what gets displayed more directly.

Some MUAs might still display something different if there is a separate Sender: header, which some systems automatically add when you override the default. If you need detailed control over these things, you will probably also need to separately configure your MTA (Postfix, Sendmail, what have you).

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • thanks it works, what is the difference between mailx and mail? – YaRmgl Mar 28 '22 at 08:19
  • [It's complicated.](https://stackoverflow.com/a/48588035/874188) But I used `mailx` here by pure oversight. For `mailutils` on Ubuntu, I don't think it matters, out of the box. – tripleee Mar 28 '22 at 08:47
0

When system processes are sending email notifications and you don't have control over the mailx command line to add the From header, you can set a user's display name using

sudo chfn -f "*Display Name*" <user>

Emails from user will appear as being from Display Name in your email client.

Lastly, mailutils supports per-user configuration files, like ~/.mailx You can set a user's email address there with

address {
  email-addr <email: address>;
};

Further explained in mailx's --config-help option. These techniques worked on Ubuntu LTS 22.04.

TimH
  • 1
  • 1