Well, I do a lot of testing and developing of/with web application. Mostly testing of Web Softwares and plugins requires mail functionality, for example self-service password forgot function and others. Using ISPs smtp server for these is rather difficult at times and some requires hacking the code. Setting up a local mail transfer agent (mta) has become a top most requirement. I use Ubuntu Linux and the default seems to be sendmail but I have been struggling to setup sendmail as a smarthost (to use gmail to relay emails). The configuration was harder than I thought. So I switched to postfix and was able to setup a local mail server within minutes. Here follows the setups for my future references and for anyone who need this.
1. Install postfix and certificates
sudo apt-get install postfix libsasl2-2 libsasl2-modules ca-certificates
In the install wizard that follows select Internet with smarthost and add [smtp.gmail.com]:587 as the relayhost
inet_interfaces = all
mydestination = mail.yusufge.local, yusuf-ET1665, localhost.localdomain, localhost
home_mailbox = Maildir/
Just below the line that says relayhost = [smtp.gmail.com]:587
add the following
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/gmail_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_use_tls = yes
3. Add SMTP authenticating user/password and adjust the file
As sudo create and add the following to /etc/postfix/gmail_passwd
Next adjust the permission of this newly created file
sudo chmod 700 /etc/postfix/gmail_passwd
Also translate this file to a db file that postfix can understand
sudo postmap /etc/postfix/gmail_passwd
4. Restart the postfix
sudo /etc/init.d/postfix restart
With the above 4 step your local mail server will be up and running so let us test it. In the terminal:
telnet localhost smtp
Connected to localhost.
Escape character is ‘^]’.
220 yusuf-ET1665 ESMTP Postfix (Ubuntu)
250 2.1.0 Ok
250 2.1.0 Ok
354 End data with
250 2.0.0 Ok: queued as DCB0717E0141
221 2.0.0 Bye
Connection closed by foreign host.
Instead of yusuf, use your box username or a valid email address above in the mail from: and rcpt to:, but if you use any other name than the gmail account that you authenticated with, it will end up as spam or rejected by some mail severs.
Also note, do not use this for high traffic servers, only recommended for home based setup for testing. In addition, the Google account that you use will store all outgoing messages (via Internet) in the Google Send Mail folder!
As for in my testing, the mail will end up in the following folder at: /home/yusuf/Maildir/new
To check the content of the file type cat the file (you can use tab key auto complete)
Received: from localhost (localhost [127.0.0.1])
by yusuf-ET1665 (Postfix) with ESMTP id DCB0717E0141
Date: Fri, 23 Sep 2011 00:56:51 +0500 (MVT)