1

Using postfix to send mail through GMail


Normally you can install a Mail Transport Agent (MTA) like postfix or exim to serve as a mail server on any computer connected to the internet with a public IP address assigned. However, due to the problem of SPAM, many Internet mail servers block mail from unauthenticated dynamic IP addresses, which are common in domestic connections.

One of the existing solutions is to install a mail server that sends mail directly to the target server, but use Google Mail (GMail) to retrasmita messages.

To send mail using GMail SMTP server ( smtp.gmail.com ) the connection must be encrypted with TLS. For that we need three elements:

  1. Authenticated by a certificate authority certificate valid for GMail.
  2. A GMail account.
  3. A local MTA.

Installation

First install Postfix, a fairly complete and configurable MTA. Open a root terminal (Applications> Accessories> Root Terminal) and type the following command:

 aptitude install postfix

Note: Postfix conflicts with Exim, but it is safe to remove exim for postfix.

The facility will make us some questions:

  1. Configuration type: here will respond "Web Site".
  2. Name of the mail system: here we will put the domain name of our local mail server. For our case, we can put the same domain name of our PC. eg "micasa".

Usually, the installation must be completed existosamente.

Configuration

Next you need to edit the file /etc/postfix/main.cf and add the following lines to the bottom:

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

In summary, here we are telling postfix to use relayhost to connect to the Gmail server, using smtp_sasl_password_maps to extract the data connection and use SASL smtp_tls_CAfile as a certificate for secure connection.

Authentication

We must create the file /etc/postfix/sasl/passwd with the following contents:

[smtp.gmail.com]:587    [CUENTA]@gmail.com:[CONTRASEÑA]

For example:

 echo "[smtp.gmail.com]:587    luis@gmail.com:123456" > / etc / postfix / sasl / passwd 

And we protect it properly:

 chmod 600 / etc / postfix / sasl / passwd 

Then you must convert the file to a hash indexed file using the statement:

postmap / etc / postfix / sasl / passwd 

Which will create the file /etc/postfix/sasl/passwd.db

Certification

We have installed the SSL certificates of certification authorities to perform this step. We can install with:

 aptitude install ca-certificates

To add the Equifax certificate authority (which certifies emails from Gmail) to file certificates that use postfix, run the following command in a root console:

 cat / etc / ssl / certs / Equifax_Secure_CA.pem > / etc / postfix / cacert.pem

Commissioning

Finally, restart postfix to apply the changes as well:

 / etc / init.d / postfix restart

We can check the operation by opening two consoles. In an execute the following command to monitor the behavior of mail (as root):

 tail -f / var / log / mail.log

And in the other send a mail:

 echo "Éste es un correo de prueba" | mail prueba @ gmail.com

If we did things right, on the other console should look something like this:

Dec 18 18:33:40 OKComputer postfix/pickup[10945]: 75D4A243BD: uid=0 from=
Dec 18 18:33:40 OKComputer postfix/cleanup[10951]: 75D4A243BD: message-id=
Dec 18 18:33:40 OKComputer postfix/qmgr[10946]: 75D4A243BD: from=, size=403, nrcpt=1 (queue active)
Dec 18 18:33:44 OKComputer postfix/smtp[10953]: 75D4A243BD: to=
, relay=smtp.gmail.com[74.125.93.109]:587, delay=3.7, delays=0.15/0.14/1.8/1.6, dsn=2.0.0, status=sent (250 2.0.0 OK 1324249500 eb5sm36008464qab.10)
Dec 18 18:33:44 OKComputer postfix/qmgr[10946]: 75D4A243BD: removed

I hope it will be useful :)



ACTIONS

I am a young Venezuelan who loves to read and write. Telecom Engineer, lover of technology, and Free Software. I started working as a developer of Canaima GNU / Linux in 2009 and now has become one of my most enjoyable hobbies. If you like what I write here, I invite you to follow me on twitter , facebook , or RSS updates .

ABOUT LUIS ALEJANDRO

Related Articles

  • In Hunting Bears have not written anything like this before.

There are 1 opinions about this entry.

  1. open Sylar says:

    In this case .. The sender would see as "luis@gmail.com: 123456" .... No.? there is a way that the sender is user@midominio.com ¿?

    In this way .. The delivery to Gmail SMTP server ... But if you send an email loquesea@hotmail.com .. Mark it as spam .. Regards

You can give your opinions in the following form.





The "Website" is optional. Your email will not be published.