quarta-feira, 13 de junho de 2018

Make postfix relay through plain smtp authenticated account and Mutt

Make postfix relay through plain smtp authenticated account and Mutt
How send plain SMTP authentication with postfix.

I had to tested this on centos 7.3 with Selinux and iptables disabled.

Prerequisites:

yum install cyrus-sasl cyrus-sasl-plain cyrus-sasl-md5 postfix -y

Edit postfix configuration (vi /etc/postfix/main.cf):


relayhost = [smtp.myserver.com.br]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_type = cyrus
#smtp_sasl_mechanism_filter = plain, login
smtp_sasl_mechanism_filter = login, plain, md5
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtp_cname_overrides_servername = no
#smtp_sasl_security_options = noplaintext, noanonymous
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt


Some say server should be between [brackets], but not my case. In /etc/postfix/sasl_passwd you should set the user/password you want to use:

your.smtp.server:25 user.name:password


Generate the map file:

postmap hash:/etc/postfix/sasl_passwd

to test:
open new terminal and put:

tail -f /var/log/maillog

and in another terminal send a test:


echo "testing mailing" | mail -r 'reportservices@.myserver.com.br (Report Borg)' -s 'teste' user@myserver.com.br


if is ok, go to mutt for send HTML mail

first edit .muttrc and putting:
set from="Report Services <reportservices myserver.com.br="">"
send-hook . "my_hdr From: Report Services <reportservices myserver.com.br="">"
set from = "Report Services <reportservices myserver.com.br="">"
set realname = "Report Services"
set content_type=text/html
set use_from=yes
set envelope_from ="yes"

test if is Ok:

echo " <html class="exame" lang="pt-BR"> <head></head>" > /tmp/report_borg.html
echo "<body><pre 12px="" font-name:arial="" font-size:="">" >> /tmp/report_borg.html
echo "==========================[Espaço em disco]====================================" >> /tmp/report_borg.html
df -h >> /tmp/report_borg.html
echo '</pre></body></html>'  >> /tmp/report_borg.html


/usr/bin/mutt   -s "[BKP] Borg Backup"`date +%d-%m-%Y::%Hh%Mm%s`  -F /root/.muttrc  borg@myserver.com.br  <  /tmp/report_borg.html

solve problens with mutt: https://gitlab.com/muttmua/mutt/wikis/MuttFaq/Header