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
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop







![Sending Email With Attachments From Unix / Linux Command [ Shell Prompt ]](http://s0.cyberciti.org/images/rp/1/8.jpg)



{ 17 comments… read them below or add one }
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
Do you have virtual UNIX user name mapping like:
user1@domain.com drealuser
???
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
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
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
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
sendmail totally ignores all changes related to masquerade, also know as:
“does not work”, or “tutorial non- helpfull”
One more thing needs to done, if sending mail as root
#C{E}root – comment out
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.
The article does not mention how to masquerade the username.
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.
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))
This absolutely does not work, in any capacity whatsoever.
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.
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.
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.
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