Linuxaria

Everything about Linux
  • Home
  • Article
    • News
  • Howto
  • Interview
  • Pills
  • Review
  • Information
    • Contribute
    • Contact me
    • Info
    • Privacy Policy
  • Links
    • GMStyle
    • Il Bloggatore
    • Linux
    • Linux Today
    • Linuxfeed
    • LinuxInsight
    • Lxer
    • ZioBudda

Sponsor

How to configure postfix as smtp relay for Gmail on Archlinux

 Howto, Pills  Add comments
Jan 032013
 

Original article by AlexioBash, posted in Italian on the website http://dark-linux.net/.

It can be very convenient, for those who use services such as zoneminder, rtorrent, etc., to have a “Gmail Relay” to send maisl from your Gmail account.
In this guide we will see how to configure postfix to send email with our account [email protected]
The guide is based on ArchLinux, but apart the installation of the packages, the configuration is the same also on other distributions such as Debian or Centos.




As first thing we need to install the packages with :

$ sudo pacman -Sy postfix ca-certificates

Once the installation is complete go into the directory where postfix keep its configuration files :

$ cd /etc/postfix

And do a copy of the default configuration, just to be sure.

$ sudo cp main.cf main.cf-old

Now open the file main.cf with your favorite editor and delete everything (with vi just type 1000 dd and copy this configuration:

daemon_directory = /usr/lib/postfix
 
myorigin = myrealdomain.com  # substitute myrealdomain.com with your domain name
mydomain = myrealdomain.com
myhostname = myrealdomain.com
 
smtp_generic_maps = hash:/etc/postfix/generic
header_checks = regexp:/etc/postfix/header_checks
 
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd_gmail
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_enforce_tls = yes
 
disable_dns_lookups = yes
 
message_size_limit = 35651584
 
smtp_destination_rate_delay = 60
relay_destination_rate_delay = 60
 
mynetworks = 127.0.0.1
 
alias_maps = hash:/etc/aliases

Save the file as main.cf and don’t forget to substitute myrealdomain.com with your real domain name, for me this would be linuxaria.com.

Now create the file /etc/postfix/sasl_passwd_gmail with your favorite editor and insert in it this line:

[smtp.gmail.com]:587             username@gmail.com:mypassword

Substitute username with your real username and mypassword with your real password.
Now add at the end of the file /etc/postfix/header_checks the following lines:

/^To:.*@hostname.localnet/ REDIRECT username@gmail.com 
/^From:(.*@myrealdomain.com[>]*)/ PREPEND Reply-To:$1

As usual substitute username with your real username and myrealdomain with your real domain name already used in the file main.cf.
Now add at the end of the file /etc/postfix/generic the following lines:

root@myrealdomain.com         username@gmail.com
root@hostname.localnet        username@gmail.com
sudoer@hostname.localnet    username@gmail.com

Guess what ?
Yes you have to substitute as usual username and myrealdomain.

Now open a terminal as root and run these commands:

$ postmap /etc/postfix/generic
$ postmap /etc/postfix/sasl_passwd_gmail
$ cat /etc/ssl/certs/Equifax_Secure_CA.pem >/etc/postfix/cacert.pem
$ ln -s /etc/postfix/aliases.db /etc/aliases.db
$ postconf -e alias_maps=hash:/etc/aliases

Start postfix with the command:

$ systemctl start postfix

Enable it at boot time with the command:

$ systemctl enable postfix

At this point, we can test the whole configuration by sending an email with the following command:

$ echo "body of the message" | mail -r "[email protected]" -s "Subject of the mail" destination@email.com

This command will send a mailwith from [email protected] to [email protected] directly from your ArchLinux.
To verify the correct transmission we can at any time view the log located at /var/log/mail.log and keep track of sent emails.

If you want to send mail remotely, for example from another PC of the same network, you first need to put in the file main.cf in the directive mynetworks the cilent ip, this will enable it to use this machine as relay, restart postfix and on the client issue the command:

$ echo "body of the message" | mail -r "[email protected]" -s "Subject of the mail" -S smtp=IPPOSTFIX destination@email.com

Replacing “IPPOSTFIX” with the IP of the machine where we have configured postfix.

If you want to enable an entire network, it is possible to include in the directive mynetworks the entire subnet, eg 192.168.0.0/24.


Popular Posts:

  • How to protect Apache with Fail2ban
  • Nightingale a Beautiful music player for Linux
  • Linux shell: Dfc – Check your disk space with style
  • Livarp – A lightweight Linux Distribution
  • How to convert YouTube Video to MP3 easily on GNU/Linux

Find me on Google+

flattr this!

 Posted by linuxari at 23:36  Tagged with: ArchLinux, ca certificates, gmail account, linux, pacman, postfix, relay

  4 Responses to “How to configure postfix as smtp relay for Gmail on Archlinux”

  1. Mike says:
    01/08/2013 at 23:43

    What about passwords that use special characters? Is there a way to quote or escape them in the sasl_passwd_gmail file?
    When I follow this I get: (SASL authentication failed; server smtp.gmail.com[173.194.79.108] said: 535-5.7.1 Username and Password not accepted. Learn more at?535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 is3sm40319265pbc.6)

    I know I have the correct password. :-)

    Reply
    • linuxari says:
      01/09/2013 at 01:23

      Hello Mike

      I’ve took a look at the man page of postmap:

      …

      The key and value are processed as is, except that surrounding white space is stripped off. Unlike with Postfix alias databases, quotes cannot be used to protect lookup keys that contain special characters such as `#’ or whitespace.

      …

      The format posted worked for me, but I’ve found another post : http://fastmail.wikia.com/wiki/ConfiguringPostfix that sugegst to substitute the @ with a # :

      Don’t forget to replace with your Fastmail username and with the domain of your Fastmail account (eg fastmail.fm, eml.cc, etc), and with your Fastmail password. The ‘#’ seems to be important, using the regular ‘@’ symbol caused authentication errors.

      Can you also do a test changing your password to one without that particular special character ?

      I hope these links can help you.
      Best regards

      Reply
  2. Aditya Raj Bhatt says:
    03/04/2013 at 12:07

    There is a small typo. You have written systemct instead of systemctl after “Start postfix with the command : “.

    Reply
    • linuxari says:
      03/04/2013 at 18:52

      Thanks Aditya, typo fixed

      Reply

 Leave a Reply Cancel reply

(required)

(required)

CAPTCHA Image
Refresh Image

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  Configuring 2 mirrored disks on Ubuntu Linux   How to easily encrypt a file with GPG on Linux
  • English
  • Italiano

Follow Me

RSS Twitter Facebook Google+

Sponsor

Popular posts

  • How to protect Apache with Fail2ban
  • Nightingale a Beautiful music player for Linux
  • Linux shell: Dfc – Check your disk space with style
  • Livarp – A lightweight Linux Distribution
  • How to convert YouTube Video to MP3 easily on GNU/Linux

Subscribe by Email

Subscribe to RSS» English by mail

Iscriviti agli RSS» Italiano via Email

Recent Comments

  • fra on Copy – A new cloud storage service with Linux Client
  • linuxari on Livarp – A lightweight Linux Distribution
  • linuxari on Copy – A new cloud storage service with Linux Client
  • linuxari on Flareget a great download manager for Linux
  • Deekshith on Copy – A new cloud storage service with Linux Client

RSS Hubpages feed

  • RamDisk on Linux : what it is and how to use it.
  • Is your Password safe ?
  • Introduction to AnoN-1mOS a new Linux Distribution
  • 5 Popular Paid Games for Linux
  • 6 Torrent clients for Linux
© 2013 Linuxaria All site content, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Suffusion theme by Sayontan Sinha