Ubuntu, Postfix, and Gmail Relays

The Problem

You have a shiny new Ubuntu server (like mine - thank you anonymous benefactor) and you need the system to be able to send mail. You DON'T need it to accept mail for your domain though because, like me, you're using Google Apps to do that.

The Solution

Getting this to work isn't terribly difficult, though it is linux, so be prepared for even this to go horribly wrong. Because it did for me. Spare yourself the hassle of spending your day on Google reading forum posts from 2004 that have no solution. Just don't do it.

Also, on the off chance it's now 2027 and you just found my blog page after searching for a solution for 3 days, this was done on Ubuntu 12.04. Sorry future boy, but this probably won't help you much on Ubuntu 73.3 :P

First, you'll need to get the packages:

sudo apt-get install postfix libsasl2 ca-certificates libsasl2-modules


Next, configure Postfix. Every guide I've seen says to set it up as "internet server" so go with that. Follow the prompts you're given, if you're lucky enough to see them - because I wasn't. So don't be surprised if it "just happens" and you're left at the command line wondering why it's not doing what you thought it should.

You can try sacrificing a goat, assuming that's still legal in 2027. If not, try sudo dbpkg postfix reconfigure

Now you need to modify the default configuration file to match up with your Gmail setup. In /etc/postfix/main.cf, add the following section:

relayhost = [smtp.googlemail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes


That tells Postfix to use Google for the SMTP relay, using your credentials, and also where to find those.

Now you need to build the password file that will hold your credentials:

sudo nano /etc/postfix/sasl_passwd


Add the following:

[smtp.googlemail.com]:587 user.name@gmail.com:password


Change the "user.name" part to your actual username on Gmail, and change the "gmail.com" part to your domain if you're handing it there. Otherwise leave it as "gmail.com" if your'e trying to relay through a regular Gmail account.

Once the file is saved, change the permissions on it so that evil hackers can't snoop the data:

sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd


Now you need to validate the security certificate:

cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem


This last bit is the critical component, the one that stymied me for hours, and the one that NO OTHER GUIDE has ever mentioned. If you're *NOT* going to be using your Postfix server to receive mail on your domain, you need to change one line in the /etc/postfix/main.cf file:

The "mydestination" line, which should be changed to read as this:

mydestination = localhost


Now restart Postfix:

sudo /etc/init.d/postfix reload


You should be good to go now. If not, then I really feel sorry for you folks in 2027. Linux obviously hasn't gotten any easier to work with!
.........................
RIP United States of America

July 1776 - November 2012.

       
« Google Top Ten 2012
State of the Union 2013 »

Posted on Jan 25, 2013 8:43 pm by Samson in: | 4 comment(s) [Closed]
Comments
Samson said:

Also, on the off chance it's now 2027 and you just found my blog page after searching for a solution for 3 days, this was done on Ubuntu 12.04. Sorry future boy, but this probably won't help you much on Ubuntu 73.3 :P


Hahah, that made me laugh.

       
Is a chicken an adequate sacrifice in place of a goat? It's all I have on hand. :geek:

       
They'll do in a pinch, but you might need 2 of them to make up the mass difference.

       
Thanks for the walk through, Samson, I think I can use that even though my box keeps telling me it doesn't have space to upgrade to 12.04 (what's wrong with the totally blank 125gb partition, I have no clue, but...).

Having raised both goats and chickens here, I can assure you that it takes considerably more than two chicken to make up for the mass difference. A LARGE chicken might weigh in at 3-5 pounds, a small goat will weigh in at 25-30 pounds.. you do the math! :P ...now, if we were talking about productivity difference, you might need several goats to equate to a single egg-layer, but we were talking about mass. ;)

       
<< prev 1 next >>
Comments Closed
Comments for this entry have been closed.
Anonymous
Register

Forgot Password?

SuMoTuWeThFrSa
 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31  

Click for Chino, California Forecast