Sendmail + SMTP GMAIL

Publicado por Rodrigo em 28/03/2007

[ Hits: 50.235 ]

 


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

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

Outras dicas deste autor

Placa de rede Sundance

Programas do governo + firewall (iptables)

Leitura recomendada

Como Jogar Pokemon GO no Linux

Computador de mão Nokia com Linux embarcado

Migração de sistema... Porque deu errado?

Integração de autenticação Squid com NIS

Pegar MMS de rádios online e salvar as músicas em segundos

  

Comentários
[1] Comentário enviado por k1k0 em 30/03/2007 - 15:47h

correcao
troque
# openssl dsparam 1024 -out dsa1024.pem
por
# openssl dsaparam 1024 -out dsa1024.pem

Me desculpem mas faltou um "a" o certo eh dsaparam

[2] Comentário enviado por donardo em 30/03/2007 - 15:48h

Bah eu ia mesmo comentar isso :)

Valeu!

[3] Comentário enviado por kamik em 26/07/2007 - 20:11h

ei, o meu está dando esse erro no log, alguém sabe me dizer o q faço pra arrumar?
Jul 26 18:51:11 localhost sm-mta[26254]: STARTTLS: read error=generic SSL error (-1), errno=0, get_error=error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number, retry=1, ssl_err=1

[4] Comentário enviado por adilsom em 04/05/2010 - 16:05h

ola, pra fazer com um email meu mesmo da minha empresa, ex: info@asterisk-voippbx.com, é igual?


[5] Comentário enviado por diegosilveira em 01/05/2021 - 18:53h


Olá!
Quando eu rodo o comando:
# openssl dsaparam 1024 -out dsa1024.pem
ele trava, não sai do lugar e não da uma mensagem de erro.
Estou usando o debian 10

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"



Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts