Postfix masquerading or changing outgoing SMTP email or mail address

by on December 28, 2006 · 14 comments· LAST UPDATED December 28, 2006

in , ,

Address rewriting allows changing outgoing email ID or domain name itself. This is good for hiding internal user names. For example:
SMTP user: tom-01
EMAIL ID: tom@domain.com
Server name: server01.hosting.com

However when tom-01 send an email from shell prompt or using php it looks like it was send from tom-01@server01.hosting.com

In some cases internal hosts have no valid Internet domain name, and instead use a name such as localdomain.local or something else. This can be a problem when you want to send mail over the Internet, because many mail servers reject mail addresses with invalid domain names to avoid spam.

Postfix MTA offers smtp_generic_maps parameter. You can specify lookup tables that replace local mail addresses by valid Internet addresses when mail leaves the machine via SMTP.

Open your main.cf file
# vi /etc/postfix/main.cf

Append following parameter
smtp_generic_maps = hash:/etc/postfix/generic

Save and close the file. Open /etc/postfix/generic file:
# vi /etc/postfix/generic

Make sure tom-01@server01.hosting.com change to tom@domain.com
tom-01@server01.hosting.com tom@domain.com

Save and close the file. Create or update generic postfix table:
# postmap /etc/postfix/generic

Restart postfix:
# /etc/init.d/postfix restart

When mail is sent to a remote host via SMTP this replaces tom-01@server01.hosting.com by tom@domain.com mail address. You can use this trick to replace address with your ISP address if you are connected via local SMTP.

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

{ 14 comments… read them below or add one }

1 Adam K December 28, 2006 at 6:03 pm

Hey, wasn’t sure where to contact you so I’ll leave it here.. I’m tagging you with the blog tag. Check out my post for more info :)

http://www.foogazi.com/2006/12/28/tag-im-it-5-things-you-did-not-know-about-me/

Reply

2 nixCraft December 28, 2006 at 9:29 pm

Thanks for tagging me. I have just posted my own list.

Appreciate your post.

Reply

3 Drew January 19, 2008 at 5:30 am

Thanks this was helpful. I needed to be able to get my home server to forward mdadm alerts to my external email address through my isp’s smtp server (cox cable) and this was the missing piece.

Reply

4 Ejler Ottesen June 22, 2008 at 2:02 pm

I get this strange message from smtp.com in /var/spool/postfix/defer
I have found this message
for EVERY mail attempted sent via Postfix:

: host smtp.com.inbound10.mxlogic.net[208.65.144.3] said: 451
Could not load DRD for domain (1base.com) rcpt (eo@1base.com) (in reply to
RCPT TO command)
recipient=eo@1base.com
offset=133
status=4.0.0
action=delayed
reason=host smtp.com.inbound10.mxlogic.net[208.65.144.3] said: 451 Could not
load DRD for domain (1base.com) rcpt (eo@1base.com) (in reply to RCPT TO
command)

Reply

5 فروشگاه اینترنتی July 4, 2008 at 2:34 pm

Thanks this was helpful. I needed to be able to get my home server to forward mdadm alerts to my external email address through my isp’s smtp server

Reply

6 anil February 19, 2009 at 5:22 am

Dear
Can you explain same for sendmail also.

Reply

7 Gagan Brahmi March 24, 2009 at 2:57 pm

Hey Vivek,

I would like something similar done, but only for one email address and not all the emails being sent out.

Any ideas?

Reply

8 Patrick January 25, 2010 at 9:04 pm

This was a big help, thank you!

Gagan, those instructions work for just one email (that was all I needed to do too.

Reply

9 Dropdigger February 27, 2011 at 9:01 pm

Worked great – it’s now sending mail from the correct address. But postfix says my name is ‘root’ – any easy way to change that?

Reply

10 Prahmod March 3, 2011 at 9:23 am

hi,
i am using postfix and currently i can use any email address to specify FROM id.
so it is like faking any email address. smtp use can change his/her from email address. so i was wanting to change the from email address to the one with the same username.
for example: user live can send email from herry@domain.com but i want to restrict all user to use there own email address and own domains.
i want to restrict user live to send mail only from live@domain.com not any other like anyuser@anydomain.com
any help will highly be appreciated
greeting from Nepal,
~prahmod

Reply

11 etrusk July 15, 2011 at 11:37 am

Thx a lot. A postfix is transforming more and more to a sendmail.
:-)

Reply

12 alice February 22, 2012 at 6:28 am

Hi, I liked your article but don’t know exactly if my question is answered by your article. Actually I receive email from a particular domain where they change the source domain in email to my domain (for example abc@source-domain.com is changed to abc@receiver-domain.com) On reading complete headers the real domain is revealed but in From: header they put a fake address as abc@recevier-domain.com, where receiver-domain is my domain. How they do it? Is it legal and if so then what is the purpose?

Reply

13 Prahmod February 22, 2012 at 12:04 pm

@alice that is actually illegal but one can easy forge their domain and use any domain name if they own a mail server…Generally these type of activities are done by spammers to spam and sometime even by attackers to create a certain email to seem like a mail originating from the legitimate domain..
To control this type of forgery one can use dns service to update their SPF. https://en.wikipedia.org/wiki/Sender_Policy_Framework
so that email originating from a particular ip are treated as genuine and other then that ip with that domain name as spam..
Google, yahoo and other mail provider use this technique to know that email are send from the allowed ip or not

Reply

14 Dave July 4, 2012 at 2:26 pm

Thanks for a great post on Postfix masquerading or changing outgoing SMTP email or mail address. This is very helpful for a newbie like me.

Reply

Leave a Comment

Previous post:

Next post: