Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a domain, let's call it foobar.com. All of the MX records for foobar.com point to Google's mail servers because I am using Google Apps for your domain to manage it. It's great because everyone gets all the advantages of GMail, but our e-mail addresses aren't @gmail.com.

I also have a server. Primarily, it's a web server, but it also serves other things. One of the things it serves is the web site for foobar.com and also sites for various virtual hosts such as shop.foobar.com and forum.foobar.com. The server is running Ubuntu 8.04, because I like using LTS releases in production.

The thing is, there are various applications running on the server that need the ability to send out emails. Various applications, like the cron jobs, send me e-mails in case of errors. Some of the web applications need to send e-mail to users when they forget their passwords, to confirm new registered users, etc. Lastly, it's nice to be able to send e-mail from the command line using the mail command, or mutt.

How can I setup the mail on the web server to go through the Google apps mail servers? I don't need the web server to receive mail, though that would be cool. I do need it to be able to send mail as any legitimate address @foobar.com. That way the forum application can send mails with forum@foobar.com in the from field, and the ecommerce application will have shop@foobar.com in the from field. Also, by sending the mail through the Google servers, we can avoid a lot of the problems with the e-mails being blocked by various spam filters on the web. Google's SMTP servers are trusted a lot more than mine would be.

I'm pretty good with administering Linux systems, but I am absolutely brain dead when it comes to e-mail. I need step by step directions from beginning to end on how to set this up. I need to know every thing to install, and every single change to the configuration files that is necessary. I have tried following various howtos and guides in the past, but none of them were quite right. Either they didn't work at all, or they offered a configuration that is not what I wanted.

Please help. Thanks.

share|improve this question
add comment

6 Answers

up vote 15 down vote accepted

Easiest way to do this is to avoid using exim and to use sSMTP which is a lightweight MTA.

All you need to do is install it:

sudo apt-get install ssmtp mailutils

and configure it (edit /etc/ssmtp/ssmtp.conf) to use your Google Mail servers see:

root=noreply@yourdomain.com
mailhub=smtp.gmail.com:587
UseSTARTTLS=yes
UseTLS=yes
AuthUser=youremail@yourdomain.com
AuthPass=password
FromLineOverride=YES

I've been using this set-up for a while now and it just works - It's also nice to not need to be running exim when it's not necessary and let Google's mail servers handle everything for you.

share|improve this answer
    
Sweet! It totally worked. You are my hero. –  Apreche Aug 14 '09 at 23:24
    
@muffinresearch : Could you help with my situation described here serverfault.com/questions/296764/… –  nikhil Aug 2 '11 at 17:59
    
I got this message; Package mailx is a virtual package provided by: mailutils 1:2.2+dfsg1-3 heirloom-mailx 12.5-1build1 bsd-mailx 8.1.2-0.20100314cvs-1 You should explicitly select one to install. E: Package 'mailx' has no installation candidate –  Yasin Okumus Jan 1 '12 at 0:33
add comment

Basically, it's very easy.

$ sudo dpkg-reconfigure exim4-config

Choose all things that make sense for you - as long as you choose something with a smarthost. When the question that asks you what smarthost to use comes, answer: smtp.gmail.com::587

Then edit the file /etc/exim4/passwd.client to match

gmail-smtp.l.google.com:login@yourappdomain.com:p@sSw0rd
*.google.com:login@yourappdomain.com:p@sSw0rd
smtp.gmail.com:login@yourappdomain.com:p@sSw0rd

And that does the job.

ssmtp also works fine, but appeared rather slow for mail delivery. Also, I prefer to have a deamon to connect to.

share|improve this answer
add comment

Keep in mind that free version of GMail has an outbound limit of ~500 messages / day. If you don't exceed this limit muffin's solution would work great for you.

share|improve this answer
    
If I exceeded that many e-mails I would get a dedicated mail sending service. –  Apreche Oct 9 '09 at 11:29
add comment

You should be able to use Google's mail servers as your SMTP gateway and authenticate with a user.

http://www.google.com/support/a/bin/answer.py?hl=en&answer=60730

Here's some basic psudocode to give you an idea:

smtpHost = smtp.gmail.com
smtpUsername = name@domain.com
smtpPassword = your_password
smtpType = tls
smtpPort = 465

UPDATE:

Here's a link which might help a little. Its not EXACTLY what I was looking for but reasonable enough (I hope) to give you an idea that it is possible to have cron jobs send email via google apps.

http://bakingnoodles.com/tag/linux/

This little app might prove useful as well (warning: I have not tried it myself)

http://linux.softpedia.com/get/Communications/Email/Email-2-6805.shtml


Another option might be to configure Postfix to use Google Apps for all of your mail delivery. If you search google for "configure postfix google apps" you'll find a bunch of links, including this one:

http://blog.twinklesprings.com/2008/03/27/remote-mail-delivery-for-google-apps-and-postfix-mail-server/

share|improve this answer
    
Does Ubuntu use postfix, or exim? If its exim like Debian, then dpkg-reconfigure exim4-config should give you the option of sending mail through a smarthost, and you should be able top configure that to gmail. –  derobert Aug 14 '09 at 6:22
    
Postfix is the default Mail Transfer Agent (MTA) in Ubuntu. At least for 8.04 I believe. –  KPWINC Aug 14 '09 at 6:31
    
I can't do the gateway options because I have the free Google Apps, not the pay version. Also, gateway doesn't seem like it does exactly what I want. I don't want to route any mails through my server. I just want the server to be able to send mails with any from address @mydomain. Also, I have tried smarthost in the past. It works, but all emails going out are labled as being from the user that I use to authenticate the smarthost. –  Apreche Aug 14 '09 at 10:26
add comment

If you don't need to receive mail, you really don't need to send it through Google. If you setup your DNS records correctly, you should be able to send mail from the MTA on the web server.

If you are using SPF you'll want to make sure you update it to include your application server.

share|improve this answer
add comment

It is quite simple in postfix:

nano /etc/postfix/main.cnf

change the following

mydestination = mydomain.com, localhost.mydomain.com, localhost

to

mydestination = localhost.mydomain.com, localhost

reboot your server and you're done!

share|improve this answer
    
This fixed my problem. –  dguaraglia Nov 16 '11 at 1:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.