Sendmail masquerade outgoing email address

by Vivek Gite on November 2, 2006 · 16 comments

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 user@cyberciti.biz instead of realunixuser@server01.cyberciti.biz. 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/sendmail.mc:
# vi /etc/mail/sendmail.mc
Append/add/modify the lines as follows:
MASQUERADE_AS(cyberciti.biz)dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
MASQUERADE_DOMAIN(cyberciti.biz)dnl

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

Further reading

=> Masquerading and relaying

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 16 comments… read them below or add one }

1 didier November 16, 2006

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.
-Didier

Reply

2 nixcraft November 17, 2006

Do you have virtual UNIX user name mapping like:
user1@domain.com drealuser

???

Reply

3 didier November 20, 2006

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 invitation@.com (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.
-Didier

Reply

4 ifti February 16, 2009

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 root@localhos.localdomain i want to masquerade it to say test@xyz.com, nix and didier any help will be highly appreciable….
thanks

Reply

5 Mrmartin February 17, 2010

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?

Thanks

Reply

6 Shai May 11, 2010

Make sure that you have placed the above 4 lines above the MAILER lines at the end or you’ll get an error when issuing the m4 cmd from cli

Reply

7 josh from america May 11, 2010

sendmail totally ignores all changes related to masquerade, also know as:

“does not work”, or “tutorial non- helpfull”

Reply

8 J James May 18, 2010

One more thing needs to done, if sending mail as root
#C{E}root – comment out

Reply

9 Anon July 7, 2010

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

EXPOSED_USER(`root’)dnl

to

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.

Reply

10 vmunix August 12, 2010

The article does not mention how to masquerade the username.

Reply

11 ipkwena September 14, 2010

Thanks for the article. Now I have managed to have my Linux box send out emails. However, I have not resolved masquerading the user name. There must be a tutorial somewhere.

Regards.

Reply

12 Salam November 7, 2010

I followed all instructions, added the 4 lines, added an alias to my root in usersgeeneric table
root myemail@mydomain.com

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

which I didnt touch.
Whenever I issue the following command
echo “hello worls” | mail -s “Firstmail” myscondemail@anotherdoamin.fr

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))

Reply

13 Josh from America April 6, 2011

This absolutely does not work, in any capacity whatsoever.

Reply

14 jeffrey smith June 21, 2011

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

127.0.0.1 server1 server1.domain.com server1.domain.local

Then chnage the entries so they are.

MASQUERADE_AS(domain.com)dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
MASQUERADE_DOMAIN(localhost)dnl

As stated above this only works for non root users.

Reply

15 Habib Mumin January 2, 2012

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

C{E}root

remove word ‘root’ and you have

C{E}

restart sendmail as per above instructions.

There is no need to edit hosts file.

Reply

16 Sandeep February 3, 2012

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?

Thanks,
Sandeep.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 5 + 15 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.



Previous post:

Next post: