22

My root user send emails with ssmtp. However I can't change "From: root ..." root name. Is there any way to send email with another name without using another user?

Tried:

echo 'From: "New name" ' | ssmtp to@gmail.com -v

Adrian
  • 221
  • 1
  • 2
  • 3
  • @cornernote's answer should be the solution here. Also check there: https://stackoverflow.com/questions/26202791/how-to-change-sender-name-in-ssmtp – visit1985 Jun 25 '18 at 12:27

8 Answers8

21

You can set up a reverse alias in /etc/ssmtp/revaliases

root:someone@yourdomain.tld

it's hidden at the bottom of the man page.

Dave Hollingworth
  • 167
  • 1
  • 2
  • 9
user9517
  • 114,104
  • 20
  • 206
  • 289
12

Add the following in Your /etc/ssmtp/ssmtp.conf file and You will capable to set any name and email during runtime :

FromLineOverride=YES
Fedir RYKHTIK
  • 577
  • 8
  • 18
  • This is simpler than messing with `/etc/ssmtp/revaliases`, especially when `ssmtp` is run with `-t -Cssmtp.conf`. – gavenkoa Mar 29 '21 at 12:12
8

I suggest you switch from ssmtp to msmtp since ssmtp is not actively developed any more. msmtp provides all the same features as ssmtp plus more. In particular, with msmtp you can set the from setting to control who the mail appears to be sent from.

Phil Hollenback
  • 14,647
  • 4
  • 34
  • 51
  • 3
    This is not quite true - even in 2018 sSMTP seems widely used for it's simplest tasks. For instance all Ubuntu LTS releases ship with latest avail sSMTP package. It does it's job. – stamster Jan 30 '18 at 16:58
  • I was able to do that with msmtp with `set_from_header on`. An aliases file with a `default: ...` entry is also useful – piec Sep 28 '21 at 15:57
5

Try option -Ffull_name, ex:

ssmtp login@mail.com -F"Look at me" 

i'll change full name.
there is also -f for changing sender email, ex:

ssmtp -f"helper@world" -F"SuperHero" save@our.world
4

Change the 'From' text by editing /etc/passwd to receive mail from 'YOUR NAME HERE' instead of just 'root'.

chfn -f 'YOUR NAME HERE' root

Check it using grep root /etc/passwd

root:x:0:0:YOUR NAME HERE,,,:/root:/bin/bash

Found it here and it worked a treat!

cornernote
  • 149
  • 3
3

Looks like FromLineOverride=YES doesn't work anymore.

I guess GMAIL is not allowing this now. But I am not sure.

limi
  • 131
  • 2
1

I'm also using ssmtp and, even though I tried the other solutions, none of them worked for me.

However, it worked for me with GMail by defining the "From" field as:

...
From: Your Name Here <your_email_here@gmail.com>
...

I hope this helps!

SRG
  • 111
  • 3
  • This works for overriding the name, but not the address. It still shows as whatever your real gmail address is that is acting as the SMTP relay. – NeuroXc May 24 '22 at 03:13
0

The -F option works if you are specifying the email params on the ssmtp command line, e.g.

echo "Test email" | ssmtp -F"New name" -v to@gmail.com

If you want all emails sent from root@ to come from a certain name, you can change the Linux user information as described in this StackOverflow answer:

chfn -f "New name" root

"What this does is setting/changing the real name for that user in the finger information (stored in the /etc/passwd file--see the chfn man page)."

Update Even after updating the finger information, cron is still sending email from "root", not using my "New name". Some versions of cron support a MAILFROM= line, but not mine (see this article).

Mark Berry
  • 263
  • 3
  • 18