Sendmail + SMTP GMAIL
Dica publicada em Linux / Introdução
Sendmail + SMTP GMAIL
Sendmail
Primeiro crie o arquivo para autenticação no gmail contendo as informações de login e senha.# mkdir /etc/mail/auth
# touch /etc/mail/auth/client-info
# cd /etc/mail/auth
Agora vamos inserir as informações no arquivo client-info.
# echo 'AuthInfo:smtp.gmail.com "U:root" "I:minhaconta@gmail.com" "P:minhasenha"' >>client-info
Crie o arquivo de hash no diretório /etc/mail/auth:
# makemap hash client-info < client-info
Setando permissões:
# cd ..
# chmod 600 auth/*
# chmod 700 auth
Preparação do certificado SSL:
# cd /etc/mail
# mkdir /etc/mail/certs
# cd certs
# openssl dsparam 1024 -out dsa1024.pem
# openssl req -x509 -nodes -days 3650 -newkey dsa:dsa1024.pem -out mycert.pem -keyout mykey.pem
# ln -s mycert.pem CAcert.pem
# openssl req -x509 -new -days 3650 -key /etc/mail/certs/mykey.pem -out /etc/mail/certs/mycert.pem
# rm dsa1024.pem
Setando permissões:
# cd /etc/mail
# chmod 700 certs
# chmod 600 certs/*
Agora com o certificado pronto, crie o arquivo de configuração do sendmail. Faça uma copia do arquivo de exemplo sendmail-slackware.mc com o nome sendmail-gmail-tls.mc:
# cd /usr/share/sendmail/cf/cf/
# cp sendmail-slackware.mc sendmail-gmail-tls.mc
Edite o arquivo sendmail-gmail-tls.mc para que fique com o conteúdo abaixo:
dnl# This is the default sendmail .mc file for Slackware. To generate
dnl# the sendmail.cf file from this (perhaps after making some changes),
dnl# use the m4 files in /usr/share/sendmail/cf like this:
dnl#
dnl# cp sendmail-slackware.mc /usr/share/sendmail/cf/config.mc
dnl# cd /usr/share/sendmail/cf
dnl# sh Build config.cf
dnl#
dnl# You may then install the resulting .cf file:
dnl# cp config.cf /etc/mail/sendmail.cf
dnl#
include(`../m4/cf.m4')
dnl# Questo e' per dare un tocco di stile
VERSIONID(`setup for Slackware Linux and Gmail')dnl
OSTYPE(`linux')dnl
dnl# These settings help protect against people verifying email addresses
dnl# at your site in order to send you email that you probably don't want:
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
dnl# No timeout for ident:
define(`confTO_IDENT', `0')dnl
dnl# Enable the line below to use smrsh to restrict what sendmail can run:
dnl FEATURE(`smrsh',`/usr/sbin/smrsh')dnl
dnl# See the README in /usr/share/sendmail/cf for a ton of information on
dnl# how these options work:
dnl# FEATURE(masquerade_envelope)
FEATURE(`use_cw_file')dnl
FEATURE(`use_ct_file')dnl
FEATURE(`mailertable',`hash -o /etc/mail/mailertable.db')dnl
FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl
FEATURE(`access_db', `hash -T<TMPF> /etc/mail/access')dnl
FEATURE(`blacklist_recipients')dnl
FEATURE(`local_procmail',`',`procmail -t -Y -a $h -d $u')dnl
FEATURE(`always_add_domain')dnl
FEATURE(`redirect')dnl
dnl# Turn this feature on if you don't always have DNS, or enjoy junk mail:
dnl# FEATURE(`accept_unresolvable_domains')dnl
EXPOSED_USER(`root')dnl
dnl# qui aggiungiamo i dati di accesso
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
dnl# Also accept mail for localhost.localdomain:
LOCAL_DOMAIN(`localhost.localdomain')dnl
MAILER(local)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
dnl# qui mettiamo il server di posta in uscita e i certificati.
define(`SMART_HOST',`smtp.gmail.com')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`CERT_DIR', `MAIL_SETTINGS_DIR`'certs')dnl
define(`confCACERT_PATH', `CERT_DIR')dnl
define(`confCACERT', `CERT_DIR/CAcert.pem')dnl
define(`confSERVER_CERT', `CERT_DIR/mycert.pem')dnl
define(`confSERVER_KEY', `CERT_DIR/mykey.pem')dnl
define(`confCLIENT_CERT', `CERT_DIR/mycert.pem')dnl
define(`confCLIENT_KEY', `CERT_DIR/mykey.pem')dnl
dnl# the sendmail.cf file from this (perhaps after making some changes),
dnl# use the m4 files in /usr/share/sendmail/cf like this:
dnl#
dnl# cp sendmail-slackware.mc /usr/share/sendmail/cf/config.mc
dnl# cd /usr/share/sendmail/cf
dnl# sh Build config.cf
dnl#
dnl# You may then install the resulting .cf file:
dnl# cp config.cf /etc/mail/sendmail.cf
dnl#
include(`../m4/cf.m4')
dnl# Questo e' per dare un tocco di stile
VERSIONID(`setup for Slackware Linux and Gmail')dnl
OSTYPE(`linux')dnl
dnl# These settings help protect against people verifying email addresses
dnl# at your site in order to send you email that you probably don't want:
define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
dnl# No timeout for ident:
define(`confTO_IDENT', `0')dnl
dnl# Enable the line below to use smrsh to restrict what sendmail can run:
dnl FEATURE(`smrsh',`/usr/sbin/smrsh')dnl
dnl# See the README in /usr/share/sendmail/cf for a ton of information on
dnl# how these options work:
dnl# FEATURE(masquerade_envelope)
FEATURE(`use_cw_file')dnl
FEATURE(`use_ct_file')dnl
FEATURE(`mailertable',`hash -o /etc/mail/mailertable.db')dnl
FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable.db')dnl
FEATURE(`access_db', `hash -T<TMPF> /etc/mail/access')dnl
FEATURE(`blacklist_recipients')dnl
FEATURE(`local_procmail',`',`procmail -t -Y -a $h -d $u')dnl
FEATURE(`always_add_domain')dnl
FEATURE(`redirect')dnl
dnl# Turn this feature on if you don't always have DNS, or enjoy junk mail:
dnl# FEATURE(`accept_unresolvable_domains')dnl
EXPOSED_USER(`root')dnl
dnl# qui aggiungiamo i dati di accesso
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
dnl# Also accept mail for localhost.localdomain:
LOCAL_DOMAIN(`localhost.localdomain')dnl
MAILER(local)dnl
MAILER(smtp)dnl
MAILER(procmail)dnl
dnl# qui mettiamo il server di posta in uscita e i certificati.
define(`SMART_HOST',`smtp.gmail.com')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`CERT_DIR', `MAIL_SETTINGS_DIR`'certs')dnl
define(`confCACERT_PATH', `CERT_DIR')dnl
define(`confCACERT', `CERT_DIR/CAcert.pem')dnl
define(`confSERVER_CERT', `CERT_DIR/mycert.pem')dnl
define(`confSERVER_KEY', `CERT_DIR/mykey.pem')dnl
define(`confCLIENT_CERT', `CERT_DIR/mycert.pem')dnl
define(`confCLIENT_KEY', `CERT_DIR/mykey.pem')dnl
Crie um backup do arquivo /etc/mail/sendmail.cf:
# cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.backup
# cd /usr/share/sendmail/cf/cf/
Compilamos o arquivo através do m4:
# m4 sendmail-gmail-tls.mc > /etc/mail/sendmail.cf
Inicie o daemon:
# /etc/rc.d/rc.sendmail start
Teste final para ver se a configuração está correta:
$ echo "Testando RELAY GMAIL" | mail -s "Teste Relay Gmail" minhaconta@gmail.com.br
Bom, chegamos ao final, espero que seja útil :-)
Até a próxima.
Rodrigo Gomes Borba
k1k0borba@gmail.com
k1k0borba@hotmail.com
troque
# openssl dsparam 1024 -out dsa1024.pem
por
# openssl dsaparam 1024 -out dsa1024.pem
Me desculpem mas faltou um "a" o certo eh dsaparam