邮件服务器postfix,saslauthd,dovecot安装配置提供SMTP服务
背景:Jenkins pipeline执行完成后把结果通过email发送给相关人员。配置Jenkins E-mail notification时需要指定SMTP server。因此,需要在服务器上安装配置提供SMTP服务。
前提:linux服务器的<hostname>.<mydomain> (e.g.: abc.def.com.cn) 可通过DNS进行解析
主要参考资料,
https://www.2cto.com/os/201207/139757.html
http://www.linuxfromscratch.org/blfs/view/cvs/postlfs/cyrus-sasl.html
https://stackoverflow.com/questions/42409722/cyrus-sasl-make-failed-expected-specifier-qualifier-list-error-on-digestmd5-c
=========================
安装以下包
yum install -y gcc gcc-c++
yum install -y openssl
yum install -y sendmail
yum install -y sendmail-cf
yum install -y postfix
yum install -y patch
yum install -y autoconf
yum install -y automake
yum install -y libtool
yum install -y dovecot
=========================
vi /etc/postfix/main.cf
myhostname = <hostname>.<mydomain> // e.g.: abc.def.com.cn
mydomain = <mydomain> // e.g.: def.com.cn
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost
mynetworks_style = subnet
mynetworks = 127.0.0.0/8, localhost, <my_ip_address> // e.g.: 61.135.169.125
relay_domains = $mydestination, <mydomain> // e.g.: def.com.cn, 此处加上<mydomain>,这样就能够发信给公司邮箱了(e.g. account@def.com.cn),否则会有Relay access denied报错
home_mailbox = Maildir/ //如果采用系统帐号作为邮件用户名,该目录为帐号下的目录
最后面添加(sasl加密算法支持)
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,reject_unauth_destination,permit_mynetworks
smtpd_client_restrictions = permit_sasl_authenticated
=========================
安装Cyrus SASL
按照 http://www.linuxfromscratch.org/blfs/view/cvs/postlfs/cyrus-sasl.html 安装Cyrus SASL
其中在make时抛错,参考以下链接解决 https://stackoverflow.com/questions/42409722/cyrus-sasl-make-failed-expected-specifier-qualifier-list-error-on-digestmd5-c
cp mac/libdes/public/des.h include/
vim plugins/digestmd5.c
add #include <des.h> after #include <ctypes.h>
==========================
ln -s /etc/sasl2/smtpd.conf /usr/lib/sasl2/smtpd.conf
vim etc/sysconfig/saslauthd
MECH=shadow
vi /etc/dovecot/dovecot.conf,解注释以下两行
protocols = imap pop3 pop3s
listen = *
重启服务
service postfix restart
service dovecot restart
service saslauthd restart
设置开机自启
chkconfig –-level 2345 postfix on
chkconfig –-level 2345 dovecot on
chkconfig –-level 2345 saslauthd on
或:
echo /usr/sbin/postfix >> /etc/rc.d/rc.local
echo /usr/sbin/dovecot >> /etc/rc.d/rc.local
echo /usr/sbin/saslauthd >> /etc/rc.d/rc.local
查看log:
/var/log/maillog
/var/log/message