Postfix rewrite mail address ONLY for outgoing/sending e-mail

Written by - 0 comments

Published on - Listed in Linux Mail


In these days I have a case where I have to change the domain name of e-mail addresses which are sent out to the Internet. So all e-mails sent out to the Internet need to have the sending addresses changed.

To be more specific: Big company (bigcompany.com) bought small company (smallcompany.com) and from now on all outgoing e-mails must be sent with bigcompany.com addresses. But of course the mail server still needs to receive e-mails for smallcompany.com.

After some research I found the parameter smtp_generic_maps, which looks pretty good:

" When mail is sent to a remote host via SMTP, this replaces  his@localdomain.local by his ISP mail address, replaces her@localdomain.local by her ISP mail address, ...."

But the problem is, that my Postfix solution is a mail gateway (anti-spam, anti-virus) in front of an Exchange server. Therefore the mailboxes are not on the Postfix server and e-mails are forwarded... yes... to a remote host. So even for incoming e-mails the smtp_generic_maps parameter will be applied and smallcompany.com will be replaced by bigcompany.com (and will therefore be relayed to the MX of bigcompany.com).

So I had to look for another solution. This time I found what I was looking for: The sender_canonical_maps parameter! In the documentation the following text describes this parameter:

Example: you want to rewrite the SENDER address "user@ugly.domain" to "user@pretty.domain", while still being able to send mail to the RECIPIENT address "user@ugly.domain".

Yes - this is exactly what I need. I still need to be able to receive e-mails for ugly.domain (smallcompany.com) but all sending domains need to be changed from ugly.domain to pretty.domain (bigcompany.com).

/etc/postfix/main.cf:

# Change outgoing email addresses to be @bigcompany.com
# 01.06.2011 Claudio
sender_canonical_maps = hash:/etc/postfix/sender_canonical

/etc/postfix/sender_canonical:

@smallcompany.com       @bigcompany.com


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Icingaweb   Icingaweb2   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder   


Update cookies preferences