Sendmail masquerade outgoing email address

Posted on in Categories FreeBSD, Linux, Mail server, Security, Tuning, UNIX last updated November 2, 2006

If you just need an outgoing email from web server use sendmail. But what is masquerading?

With the help of masquerading your outgoing email appers from [email protected] instead of [email protected] This will also hide your internal user name or host name from rest of the world.

So this feature rewrites the hostname in the address of outgoing mail. This is also used when you have centralized mail server i.e. mail hub.

Sendmail masquerading configuration

Open your sendmail config file /etc/mail/
# vi /etc/mail/
Append/add/modify the lines as follows:

Save and close the file. Replace domain name with your actual domain name. Update and restat sendmail server:
# m4 /etc/mail/ > /etc/mail/
# /etc/init.d/sendmail restart

Further reading

=> Masquerading and relaying

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

21 comment

  1. Nice. So, this explains how to ‘hide’ the domain name. But what about the user name ? With the changes you describe, it still shows our real unix username. Am I missing something here ?

    thanks for your help.

  2. Hi nixcraft,

    No I haven’t set this up. To be fully honest, I am not familiar with virtual unix user name mapping. Can you explain a little bit more.

    I did try to use the virtusertable file but it didn’t to work for outgoing email. The problem I am trying to solve is EXACTLY the on you mention in your post: I have a machine (prod1) and a user (prod) and I want to send emails as [email protected] (I am just interested in outgoing email… and no, I am not a spammer 🙂

    The masquerade works for the domain name, but for the user, I ended up having to create a unix user ‘invitation’ on my box and sudo to invitation before sending the emails… It works fine but I am sure there is a better/simpler way…

    Thanks for your reply btw.

  3. i m facing the same problem as mentioned by didier , actually i have set a linux monitoring server which monitors network devices,if any device is down it sends emails on our local domain using sendmail, the outgoing mails are sent from this server like [email protected] i want to masquerade it to say [email protected], nix and didier any help will be highly appreciable….

  4. Great, simple article, how would the masquerading work if I’m using Apache virtual hosts ie more than 1 domain on the server. If a php app from one virtual host sends mail using the PHP mail() function how do I set which from address is used?


  5. To allow root to masquerade (eg: for logwatch) in change:



    dnl EXPOSED_USER(`root’)dnl

    This command bypasses masquerading for the root user, which makes it very confusing when testing this from the root account.

  6. I followed all instructions, added the 4 lines, added an alias to my root in usersgeeneric table
    root [email protected]

    Note : I already have the following 4 lines in my
    dnl MASQUERADE_DOMAIN(localhost)dnl
    dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl
    dnl MASQUERADE_DOMAIN(mydomain.lan)dnl

    which I didnt touch.
    Whenever I issue the following command
    echo “hello worls” | mail -s “Firstmail” [email protected]

    I get right away an email for root indicating :

    The following addresses had permanent fatal errors —–

    (reason: 550 5.1.8 your MAIL FROM is refused for this recipient : 553 sorry, your envelope sender domain must exist (#5.7.1))

  7. I managed to get this working by doing the following.

    change you /etc/hosts file so the first entry with a . for 127.0.01 is the domain your trying to masquerade i.e server1 server1.domain.local

    Then chnage the entries so they are.


    As stated above this only works for non root users.

    1. To allow user root to send email and use masquerade domain, in the line beginning


      remove word ‘root’ and you have


      restart sendmail as per above instructions.

      There is no need to edit hosts file.

  8. Hi Vivek,
    Small query about out going mails.
    I would like to add some disclaimer message for every outgoing mail form our mail server. Can you please suggest me the best way to do this?



    Thank you all for your comments and info… my problem was the EXPOSED_USER for ROOT that was causing me all the grief since i was testing that way…

    Thank you again

  10. Hi,

    I have configured postfix mail server whose hostname is “” but registered domain is “” [supposed] so while i send mail it returns error

    Diagnostic-Code: smtp; 553 5.1.8 … Domain of
    sender address [email protected] does not exist

    so how can i change sender domain address, it will be appreciated if i can change it without touching postfix major configuration files.


Leave a Comment