Postfix安装脚本

简介: 以下脚本在CentOS 5 上通过   #!/bin/bash # 切换到root开始安装 su - mkdir /data/Downloads/ chmod -R 777 /data/Downloads/ cd /data/Downloads/ wget http://postfix.

以下脚本在CentOS 5 上通过

 

#!/bin/bash

# 切换到root开始安装
su -
mkdir /data/Downloads/
chmod -R 777 /data/Downloads/
cd /data/Downloads/


wget http://postfix.it-austria.net/releases/official/postfix-2.7.1.tar.gz
wget ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.23.tar.gz
wget ftp://ftp.andrew.cmu.edu/pub/cyrus/cyrus-imapd-2.3.16.tar.gz
wget http://www.openssl.org/source/openssl-1.0.0a.tar.gz



#创建用户
useradd -M -s /bin/false -p* postfix
groupadd postdrop


# 安装
tar xzf openssl-1.0.0a.tar.gz
cd openssl-1.0.0a
./config --prefix=/usr/local/openssl-1.0.0a  shared threads  # -fPIC for 64 bit OS
make
make install
ln -s /usr/local/openssl-1.0.0a /usr/local/openssl


tar xzf cyrus-sasl-2.1.23.tar.gz
cd cyrus-sasl-2.1.23
./configure --prefix=/usr/local/postfix/cyrus-sasl-2.1.23 \
        --enable-login --enable-ntlm
make && make install
cd ..


tar xzf cyrus-imapd-2.3.16.tar.gz
cd cyrus-imapd-2.3.16
./configure --prefix=/usr/local/postfix/cyrus-imapd-2.3.16 --with-lock=fcntl \
        --with-sasl=/usr/local/postfix/cyrus-sasl-2.1.23 \
        --with-openssl=/usr/local/openssl
make && make install
cd ..


tar xzf postfix-2.7.1.tar.gz
cd postfix-2.7.1
make makefiles --always-make CCARGS='-I/usr/local/postfix/cyrus-sasl-2.1.23/include/sasl -I/usr/local/openssl/include -DDEF_CONFIG_DIR=\"/usr/local/postfix/etc\" -DFD_SETSIZE=2048 -DUSE_CYRUS_SASL -DUSE_TLS' \
        AUXLIBS='-L/usr/local/postfix/cyrus-sasl-2.1.23/lib/sasl2 -L/usr/local/openssl/lib -L/usr/local/openssl/lib64 -lsasl2 -lssl -lcrypto'
make
make install
#安装过程中需要回答问题,下面三个问题,请使用右边的回答,其他直接按回车用默认值
#  [/usr/bin/mailq]   /usr/bin/mailq.postfix
#  [/usr/bin/newaliases]   /usr/bin/newaliases.postfix
#  [/usr/sbin/sendmail]   /usr/sbin/sendmail.postfix
cd ..



# 添加以下内容到main.cf echo [BELOW TEXT] >> /usr/local/postfix/etc/main.cf
local_recipient_maps =
#请将所有的mail.example.com和example.com替换为您的MX域名
###############postfix#################################
myhostname = mail.example.com
myorigin = example.com
mydomain = example.com
append_dot_mydomain = no
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mynetworks = 192.168.1.0/24, 10.0.0.0/24, 127.0.0.0/8
mynetworks = 127.0.0.1  #只接收本机的本地邮件
#body_checks = regexp:/usr/local/postfix/etc/body_checks  #用于从邮件中提取信息记录到postfix日志

############################CYRUS-SASL############################
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!


# echo [BELOW TEXT] > /usr/local/postfix/etc/smtpd.conf
echo "pwcheck_method: saslauthd" >> /usr/local/postfix/etc/smtpd.conf
echo "mech_list: PLAIN LOGIN" >> /usr/local/postfix/etc/smtpd.conf

# echo [BELOW TEXT] >> /usr/local/postfix/etc/body_checks
/\/account\/([a-z_]+)\/veri/  WARN "$1"
/verify=3D([0-9a-f]+)/  WARN "$1"




# 设置
rm -f /usr/sbin/sendmail
ln -s /usr/sbin/sendmail.postfix /usr/sbin/sendmail
rm -f /etc/alternatives/mta
ln -s /usr/sbin/sendmail.postfix /etc/alternatives/mta

rm -f /usr/sbin/saslauthd
ln -s /usr/local/postfix/cyrus-sasl-2.1.23/sbin/saslauthd /usr/sbin/saslauthd
rm -rf /etc/postfix
ln -s /usr/local/postfix/etc /etc/postfix

# 启动
/etc/rc.d/init.d/sendmail stop
chkconfig sendmail off
chkconfig --list sendmail
chkconfig saslauthd on
chkconfig --list saslauthd
/etc/rc.d/init.d/saslauthd start
postfix start

# 测试,收件人为who@where.com
telnet localhost 25
EHLO mail.example.com
MAIL FROM:admin@example.com
RCPT TO:who@where.com NOTIFY=success,failure
DATA
subject:Mail test!
This is just a mail test!!!
.


#从日志中统计退回、拒收、超时失败的邮件
#grep "status=bounced" /var/log/maillog | gawk 'match($0,/to=<(.*)>/){print substr($0,RSTART+4,RLENGTH-5)}'
#grep "status=deferred" /var/log/maillog | gawk 'match($0,/to=<(.*)>/){print substr($0,RSTART+4,RLENGTH-5)}'
#grep "status=expired" /var/log/maillog | gawk 'match($0,/to=<(.*)>/){print substr($0,RSTART+4,RLENGTH-5)}'


 
目录
相关文章
|
1天前
|
运维 网络协议 Linux
【运维系列】Centos7安装并配置postfix服务
安装CentOS7的Postfix和Dovecot,配置Postfix的`main.cf`文件,包括修改完全域名、允许所有IP、启用邮箱等。然后,配置Dovecot的多个配置文件以启用auth服务和调整相关设置。重启Postfix和Dovecot,设置开机自启,并关闭防火墙进行测试。最后,创建邮箱账户并在Windows邮箱客户端中添加账户设置。
9 0
|
网络协议 Linux 网络安全
Linux服务器---邮件服务安装postfix
安装postfix      postfix是一个快速、易于管理、安全性高的邮件发送服务,可以配合dovecot实现一个完美的邮箱服务器。1、安装postfix       [root@localhost ~]# rpm -qa | grep postfix      [root@localhos...
2303 0
|
开发工具 网络安全 数据安全/隐私保护
Postfix 邮件服务器安装与配置
#!/bin/bash yum -y install postfix dovecot; #/etc/postfix/main.cf #postfix check  postfix start  postfix stop postfix flush  postfixreload #/etc/postfix/main.
1246 0
|
Linux 数据安全/隐私保护 Python
|
关系型数据库 MySQL Linux
|
关系型数据库 MySQL 数据库