📜 ⬆️ ⬇️

Configure sendmail to send mail through gmail.com

For a long time I was looking for a clear explanation of how to make a local sendmail, installed on a computer on the internal network, send mail to the outside world. As relay, smtp.gmail.com was selected.

Dug up and tried a bunch of descriptions on the network how it should be done. The result was zilch.

I propose a result of actions compiled from various sources and own mistakes, which was crowned with success. Maybe someone will save time.

System: CentOS 6.3 (2.6.32-279.el6.x86_64).
Installing the right packages:
')
uym install sendmail sendmail-cf openssl cyrus-sasl cyrus-sasl-plain nano 

Creating SSL certificates:

 mkdir /etc/mail/certs chmod 700 /etc/mail/certs cd /etc/mail/certs openssl dsaparam 1024 -out dsa1024 -out dsa1024.pem openssl req -x509 -nodes -days 3650 -newkey dsa:dsa1024.pem -out /etc/mail/certs/mycert.pem -keyout /etc/mail/certs/mykey.pem openssl req -x509 -new -days 3650 -key /etc/mail/certs/mykey.pem -out /etc/mail/certs/mycert.pem ln -s /etc/mail/certs/mycert.pem /etc/mail/certs/CAcert.pem chmod 600 /etc/mail/certs/* 

Creating a file with authentication data:

 nano /etc/mail/auth/authinfo 

 AuthInfo:smtp.gmail.com "U:root" "I:USERNAME@gmail.com" "P:PASSWORD" AuthInfo: "U:root" "I:USERNAME@gmail.com" "P:PASSWORD" 

Convert:

 makemap hash -r /etc/mail/auth/authinfo < /etc/mail/auth/authinfo 

Add the required configuration to sendmail.mc (important: do it before the first FEATURE):

 dnl # Smrp relay define(`CERT_DIR', `MAIL_SETTINGS_DIR`'certs') define(`confCACERT_PATH', `CERT_DIR') define(`confCACERT', `CERT_DIR/CAcert.pem') define(`confSERVER_CERT', `CERT_DIR/mycert.pem') define(`confSERVER_KEY', `CERT_DIR/mykey.pem') define(`confCLIENT_CERT', `CERT_DIR/mycert.pem') define(`confCLIENT_KEY', `CERT_DIR/mykey.pem') dnl # dnl # gmail auth define(`SMART_HOST',`[smtp.gmail.com]')dnl define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl define(`confAUTH_OPTIONS', `A p')dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl FEATURE(`authinfo',`hash -o /etc/mail/auth/authinfo.db')dnl 

We compile the configuration, restart sendmail and check the sending of mail:

 make -C /etc/mail service sendmail restart sendmail -f USERNAME@gmail.com -v receiver@mail.domen Test . 

Check the result:

 mailq tail maillog 

Source: https://habr.com/ru/post/281102/


All Articles