Postfix: Configurar correo por GMAIL

  • Instalamos dependencias
apt-get install openssl ssl-cert postfix mailutils openssl ssl-cert mailutils libsasl2-2 ca-certificates libsasl2-modules -y
  • Selecionamos «Sistema satélite»
  • Nombre del sistema de correo
  • Máquina de reenvío SMTP
  • Abrimos el archivo:
nano /etc/postfix/main.cf
  • Eliminamos TODO y reemplazamos con:
# SMTP relayhost
relayhost = [smtp.gmail.com]:587
## TLS Settings
smtp_tls_loglevel = 1
smtp_tls_CAfile = /etc/postfix/certs/CAcert.pem
smtp_tls_cert_file = /etc/postfix/certs/mycert.pem
smtp_tls_key_file = /etc/postfix/certs/mykey.pem
smtp_use_tls = yes
smtpd_tls_CAfile = /etc/postfix/certs/CAcert.pem
smtpd_tls_cert_file = /etc/postfix/certs/mycert.pem
smtpd_tls_key_file = /etc/postfix/certs/mykey.pem
smtpd_tls_received_header = yes
smtpd_use_tls = yes
# configuracao tls
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
# alias de mapeamento interno para externo
smtp_generic_maps = hash:/etc/postfix/generic
  • Agregamos el nombre del host
myhostname=zeus.siua.ac.cr
  • Creamos el archivo:
nano /etc/postfix/sasl_passwd
  •  Agregamos:
[smtp.gmail.com]:587   interuniversitariadealajuela@gmail.com:contraseña
  •  Creamos el archivo de alias
nano /etc/postfix/generic
  • Agregamos
root@localhost.localdomain      interuniversitariadealajuela@gmail.com
  • Cambiamos los permisos
chmod 600 /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/generic
postmap /etc/postfix/sasl_passwd
postmap /etc/postfix/generic
  • Creamos los certificados
mkdir /etc/postfix/certs/
cd /etc/postfix/certs/
openssl dsaparam -out dsaparam.pem 2048
openssl req -x509 -nodes -days 3650 -newkey dsa:dsaparam.pem -out mycert.pem -keyout mykey.pem
  • RESULTADO
Generating a 2048 bit DSA private key
writing new private key to 'mykey.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CR
State or Province Name (full name) [Some-State]:Alajuela
Locality Name (eg, city) []:Alajuela
Organization Name (eg, company) [Internet Widgits Pty Ltd]:SIUA
Organizational Unit Name (eg, section) []:UGIT
Common Name (e.g. server FQDN or YOUR name) []:UGIT
Email Address []:interuniversitariadealajuela@gmail.com
  • Eliminamos la llave
rm dsaparam.pem
  • Aplicamos
ln -s mycert.pem CAcert.pem
openssl req -x509 -new -days 3650 -key /etc/postfix/certs/mykey.pem -out /etc/postfix/certs/mycert.pem
  • RESULTADO:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CR
State or Province Name (full name) [Some-State]:Alajuela
Locality Name (eg, city) []:Alajuela
Organization Name (eg, company) [Internet Widgits Pty Ltd]:SIUA
Organizational Unit Name (eg, section) []:UGIT
Common Name (e.g. server FQDN or YOUR name) []:UGIT
Email Address []:interuniversitariadealajuela@gmail.com
  • Reiniciamos a postfix
/etc/init.d/postfix reload
  • Probamos
echo "contenido correo" | mail -s "asunto" gustavo.matamoros@gmail.com
  • Para deshabilitar la compatibilidad de versiones anteriores y eliminar el mensaje del log de postfix «Postfix is running with backwards-compatible default settings»
  • Abrimos el archivo
nano /etc/postfix/main.cf
  • Agregamos:
compatibility_level=2
  •  Reiniciamos
postfix reload