Sendmail masquerade outgoing email address

by on November 2, 2006 · 19 comments· LAST UPDATED November 2, 2006

in , ,

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

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 19 comments… read them below or add one }

1 didier November 16, 2006 at 11:14 pm

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 at 1:01 pm

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

???

Reply

3 didier November 20, 2006 at 8:17 pm

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 at 5:58 am

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 at 6:36 pm

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 at 7:19 am

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 at 7:01 pm

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 at 8:24 pm

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

Reply

9 Anon July 7, 2010 at 10:11 am

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 at 5:21 pm

The article does not mention how to masquerade the username.

Reply

11 ipkwena September 14, 2010 at 7:11 pm

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 at 7:45 pm

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 at 8:08 pm

This absolutely does not work, in any capacity whatsoever.

Reply

14 jeffrey smith June 21, 2011 at 3:59 pm

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 at 6:21 pm

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 at 6:35 am

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

17 RCRON July 27, 2012 at 12:06 am

THIS WAS ABSOLUTELY a HUGE HELP FOR ME….

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

Reply

18 karan December 26, 2012 at 1:26 pm

Hi,

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

Diagnostic-Code: smtp; 553 5.1.8 … Domain of
sender address karan@test.example.com 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.

Thanks,
Karan

Reply

19 Vijay May 28, 2013 at 7:59 pm

Sendmail.mc

MASQUERADE_AS(gsesvnadmin@gsesvn.corp.abc.com)dnl
FEATURE(masquerade_envelope)dnl
FEATURE(masquerade_entire_domain)dnl
MASQUERADE_DOMAIN(gsesvn.corp.abc.com)dnl

My expectation:

FROM: gsesvnadmin@gsesvn.corp.abc.com , but what it returns is, gsesvnadmin@.corp.abc.com

How to suppress the hostname, and get the actual output that what am passing?

Reply

Leave a Comment

Previous post:

Next post: