How do I make postfix send emails from user@mydomain instead of root@hostname? Even after installing and entering my domain when it asked, it's still being sent with the hostname and not the domain I provided. In my main.cf file

myorigin = /etc/mailname

and /etc/mailname contains:


which is my domain.

I have managed to fix my problem temporarily by changing my hostname to my domain name. However, how can I change who the email is from; currently mail is shown from root I want it to be something else.

  • How are you sending the email? Using the mail command or what? – Wildcard Jul 18 '17 at 4:56
  • Yes. I'm using echo "body" | mail -s blah email – NerdOfLinux Jul 18 '17 at 4:59
  • 2
    mail -r fromaddress. See man mail. – Wildcard Jul 18 '17 at 5:02
  • How do I fix mail coming from myhostname.mac.com? – NerdOfLinux Jul 18 '17 at 5:07
  • Did you read my previous comment? Did you check the man page and read about the -r option? Is that what you were looking for? – Wildcard Jul 18 '17 at 5:28

Postfix itself does not "set" the from address for an mail (as long has you haven't really tweaked the postfix configuration).
The from address header of an e-mail is set by the mail client which is asking postfix to deliver the mail (Postfix is a MTA).

Hence you are looking at the wrong place - as far as I understand your question.

You mentioned that you are using the mail command to test your configuration. This neat little command is - by default - using the systems user name under which the command gets executed. In your case this seems to be user root. Try executing mail as a different user and you'll see the from part changed.
And since the command mail does - by default - not append the domain part to the "from" header of the mail it hands over to postfix, postfix is appending the myorigin part automatically to root.

Though mail is not limiting you to not use some other "from" e-mail header. You can read about on the www or the manual page of mail. Also consider using sendmail.

Please note that postfix is a beast when it comes to configurability. You may accomplish almost everything you want postfix to do if you really understand its architecture and configuration files.
But since you are asking a quite 'newbee-ish' question you may not yet want to go down that road...


Using gue's and Bob Eager's answer, I figured out that the following setting in /etc/postfix/main.cf also does the job (on an Ubuntu 18.04 machine):

# appending .domain is the MUA's job.
# append_dot_mydomain = no  # --> this is the default setting
append_dot_mydomain = yes  # --> Setting it to yes appends the domain to the hostname

It also explains what gue said: appending the .domain is the Mail User Agent's job. By setting it to yes we are overriding this.

So, my setup is :

append_dot_mydomain = yes
myorigin = /etc/mailname


Still, it doesn't feel like the right way; after all by setting it to yes we are violating the principle that "appending the .domain is the Mail User Agent's job"

Furthermore, I am not sure why I need to configure it this way to make it work. I have another server (configured by someone else; a Debian 8.11 machine), which does append the domain after the hostname correctly, even with /etc/mailname being set to the domain, and with append_dot_mydomain=no. And on that server it works both for mailx and for mails sent by e.g. logcheck


You asked this twice, but I'll repeat my answer. In main.cf:

myorigin = $mydomain

If you are sending mail with a PHP script: You can set the "from" portion of the header before you execute the mail() command.


$to      = 'target@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: noreply@yourdomain.com' . "\r\n" .   // this will show up as the from address
    'Reply-To: from.email@gmail.com' . "\r\n" .        // set this as the senders email so replys will go to them
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

This is how I have stepped around this problem in my particular situation.

Depending on your situation just setting these headers should be the solution to your issue.

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.