Ubuntu – Stop local emails being sent to relay host with postfix

emaillocalpostfixrouteUbuntu

I've recently signed up to SMTP2GO (smtpcorp). I've setup postfix on one of EC2 servers and have pointed it to my smtp2go account:

relayhost = [smtpcorp.com]:2525

Now all my mail is being routed through SMTP2GO, but the issue is, that the 1000+ emails that are generated by cron job ect are being sent to SMTP2GO using the email address:

root@ec2-46-51-151-256.eu-west-1.compute.amazonaws.com

My question is, what would be the best way to stop all these "local" emails being routed to SMTP2GO?

Thanks

Martin

My main.cf:

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

append_dot_mydomain = no


readme_directory = no

smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache



myhostname = ec2-46-51-151-256.eu-west-1.compute.amazonaws.com

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname

mydestination = ec2-46-51-151-256.eu-west-1.compute.amazonaws.com, localhost.eu-west-1.compute.internal, localhost

relayhost = [smtpcorp.com]:2525
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:account:password
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
header_size_limit = 4096000
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4

Best Answer

Postfix relayhost doesn't send local mail to the relayhost normally:

From postfix.org:

relayhost (default: empty)

The next-hop destination of non-local mail; overrides non-local domains in recipient addresses. This information is overruled with relay_transport, sender_dependent_default_transport_maps, default_transport, sender_dependent_relayhost_maps and with the transport(5) table.

So if it is happenning, it is because your local mail is not identified as local. You need to include your local domain in mydestination = config line. I see you have the ec2-....amazonaws.com there but probably you have defined a local domain different than this one for your LAN. If you don't have defined a local domain, I think (needs testing) if you only add 127.0.0.1 localhost.localdomain localhost in your etc/hosts file and add localhost.localdomain to mydestination= it should be sufficient.

Related Topic