Configure host and default sender name in Linux sendmail

AXISHK used Ask the Experts™
Run sendmail –s “TEST MAIL” < /dev/null. I find the following is gmail header :

Return-Path: <root@fedoralinux20-test>
Received: from fedoralinux20-test

Where can I change  the host name and domain name used by sendmail ?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Principal Software Engineer
Sendmail is a bit of a drag as -- unlike Postfix -- the configuration files must be edited, and then recompiled.

Sendmail is, imo, overly obscure when compared to Postfix but if it's what you got, you may be stuck with it unless you can get permission to switch to Postfix.  Here's a good, brief introduction to Sendmail configuration.  (Ignore the references to the Redhat package manager.)
nociSoftware Engineer
Distinguished Expert 2018
By default the hostname is taken from the systems hostname, as return by the command  hostname
and the username the account that sends the mail.
Distinguished Expert 2017
To specify the sender <>  use the email address in conjunction with the -f option

I think you might be confusing sendmail with an email client such as mutt, mail

The configuration of the mail server, masquerade, defines the hostname that will be used when a message us being sent
There are env variables that can be set for sendmail to assemble the sender when one is not explicitly set.


Using external domain that you do not control such as gmail could be subjected by the receiving servers to the dkim, SPF, rules for the domain.


echo "To: emailaddress@domain
From: youremailaddress
Subject: test message

This is a test" | /usr/sbin/sendmail -oi -fyouremailaddress -t

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


My PHP website hosts on Apache server. Seem like it send out using user However, the apache user is not included in the php code. Any idea where will this user "apache" been setup ?

Distinguished Expert 2017

apache is the user under whose credentials httpd/apache web service runs.
you need to configure your php.ini mail to use the -f command with sendmail to set the email sender.
depending on how you are setting the message header in the PHP code, there is a way to identify who the sender should be .....
sendmail_path = /usr/sbin/sendmail -t -fsenderemail_address -oi

by default sendmail in the absence of the -f sendmail uses the logon as the username portion and its own hostname as the domain....
note the above will send all outgoing messages from your server using that sender....



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial