After stumbling upon this issue various times I’ve decided to finally resolve it.
The Issue:
If you have a domain hosted on a server, but you have setup Google Apps for your domain to use the Gmail style email system for your domain, then you might notice a problem with sending mail to your own domain.
The problem is due to the domains hosted on the server telling your SMTP server that this server is the final destination for the email and all email will be sent using the local delivery methods on Linux.
To force your mail server (in this case Postfix) to relay your emails to the Google mail servers, then you will need to change the settings in the transport file:
[12:40:21] [root@localhost /etc/postfix]# cd /
[12:46:33] [root@localhost /]# cd /etc/postfix/
[12:46:39] [root@localhost /etc/postfix]# nano transport
in the transport file you might see a line similar to:
mydomain.com maildrop:
Where “mydomain.com” is the domain you have hosted on the server.
To fix the domain relay issue to use the MX records at Google, you will need to change the above line to:
mydomain.com relay:ASPMX.L.GOOGLE.com
if you have multiple domains on the server, of which some could be a mix of google hosted or locally hosted (for email), then you can simply set the file to look something like:
mydomain.com relay:ASPMX.L.GOOGLE.com
mygoogledomain.com relay:ASPMX.L.GOOGLE.com
mylocaldomain.com maildrop:
Then run the commands:
[12:47:43] [root@localhost /etc/postfix]# postmap /etc/postfix/transport
[12:47:44] [root@localhost /etc/postfix]# /etc/init.d/postfix reload
Reloading postfix: [ OK ]
[12:47:44] [root@localhost /etc/postfix]#
You can now test your emails by sending a mail on the server to a local domain, you can do it using a simple PHP script:
< ?php
mail(“youremail@yourdomain.com”, “test – mailserver”, “Message body”);
?>
If at any time you wish to see what postfix is doing, then you can keep an eye on your log file:
[12:53:40] [root@localhost /etc/postfix]# tail -f /var/log/maillog
This will stream the maillog file and show you what postfix is doing.
[NOTE: This was carried out and tested on CentOS 5.1 but it should work on any Postfix Linux install]
Thanks for posting this fix! I had the very same problem and your fix resolved it.
I’m trying to solve the exact problem you posted about. Unfortunately, I’m still not clear on how to apply your solution.
I started from this howto:
http://behindmyscreen.newsvine.com/_news/2006/12/31/501615-configuringubuntu-postfix-and-gmail-in-101-easy-steps
Instead of mydomain.com maildrop;
I have
gmail.com smtp:[smtp.gmail.com]:587
Any suggestions? Thanks
I got it working. See my commments at the newsvine post:
http://behindmyscreen.newsvine.com/_news/2006/12/31/501615-configuringubuntu-postfix-and-gmail-in-101-easy-steps?threadId=64745&commentId=4512408#c4512408
I’m sure I can improve on what I did, so additional suggestions are welcome.
@MountainX: How did you resolve your issue
I gave all the details at the link I posted in my comment above.
http://behindmyscreen.newsvine.com/_news/2006/12/31/501615-configuringubuntu-postfix-and-gmail-in-101-easy-steps?threadId=64745&commentId=4512408#c4512408
One quick note, I have to add this line to my main.cf to work:
transport_maps = hash:/usr/local/etc/postfix/transport
Anyway, big Thanks for the description!
[...] how to set up your email to use a third-party SMTP server is beyond the scope of this article (but here’s a good one). However, a useful strategy is to run an SMTP server locally on your EC2 instance which is [...]