码迷,mamicode.com
首页 > 其他好文 > 详细

Postfix邮件系统

时间:2016-08-04 19:08:33      阅读:1061      评论:0      收藏:0      [点我收藏+]

标签:

一、           实验步骤及结果

第一阶段

                                                 部署Postfix邮件系统

 

Hostname

OS

IP

Software

www.benet.com

 

CentOS-6.5

10.0.0.2

yum install -y cyrus-sasl cyrus-sasl-devel

postfix-2.9.4.tar.gz/dovecot-2.1.10.tar.gz

 

关闭防火墙:service iptables stop

编译前配置,卸载sendmail、安装cyrus软件包

[root@www /]# yum remove -y sendmail

[root@www /]# yum install -y cyrus-sasl cyrus-sasl-devel

编译安装Postfix

[root@www /]# tar zxvf postfix-2.9.4.tar.gz -C /usr/src/

[root@www /]# cd /usr/src/postfix-2.9.4/

编译前需使用make makefiles命令调整参数,以便Postfix支持SASL认证和查询MySQL数据库

[root@www postfix-2.9.4]# make makefiles ‘CCARGS=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl‘ ‘AUXLIBS=-L/usr/lib/sasl2 -lsasl2 ‘

[root@www postfix-2.9.4]# make && make install

postconf –a            查看支持的认证方式

postconf –n            显示与默认配置不同的项

postfix start          开启postfix

postfix check        检查配置

postfixreload        重新加载

简化配置文件

[root@www ~]# postconf -n > tmp

[root@www ~]# cd /etc/postfix/

[root@www postfix]# mv main.cf main.cf.bak

[root@www postfix]# mv ~/tmp ./main.cf

[root@www postfix]# vim main.cf

inet_interfaces = 10.0.0.2, 127.0.0.1

myhostname = www.benet.com

mydomain = benet.com

myorigin = $mydomain

mydestination = $mydomain, $myhostname

home_mailbox = Maildir/

 

[root@www ~]# postfix start

postfix/postfix-script: starting the Postfix mail system

创建邮件用户、用户组

[root@www ~]# groupadd mailusers

[root@www ~]# useradd -s /sbin/nologin -g mailusers mail1

[root@www ~]# useradd -s /sbin/nologin -g mailusers mail2

[root@www ~]# passwd mail1

[root@www ~]# passwd mail2

[root@www ~]# telnet www.benet.com 25

Trying 10.0.0.2...

Connected to www.benet.com.

Escape character is ‘^]‘.

220 mail.benet.com ESMTP Postfix

HELO www.benet.com                              客户端主机地址

250 mail.benet.com

MAIL FROM:mail1@benet.com                 发件人地址

250 2.1.0 Ok

RCPT TO:mail2@benet.com                      收件人地址

250 2.1.5 Ok

DATA                                                      要传送的数据

354 End data with <CR><LF>.<CR><LF>

Subjec: A Test Mail                                 设置右键主题

T323-Y2

.                                                              点号结束

250 2.0.0 Ok: queued as 5624662052F

QUIT

221 2.0.0 Bye

Connection closed by foreign host.

 

      

第二阶段

编译安装Dovecot

[root@www /]# useradd -M -s /sbin/nologin dovecot

[root@www /]# useradd -M -s /sbin/nologin dovenull

[root@www /]# tar zxvf dovecot-2.1.10.tar.gz -C /usr/src/

[root@www dovecot-2.1.10]# ./configure --sysconfdir=/etc/

[root@www dovecot-2.1.10]# make && make install

[root@www /]# cp /usr/src/dovecot-2.1.10/doc/dovecot-initd.sh /etc/init.d/dovecot

[root@www /]# chmod +x /etc/init.d/dovecot

[root@www /]# chkconfig --add dovecot

[root@www /]# cp -R /usr/local/share/doc/dovecot/example-config/* /etc/dovecot/

[root@www /]# vim /etc/dovecot/dovecot.conf

!include conf.d/10-auth.conf

ssl = no                                                    禁止SSL机制

disable_plaintext_auth = no                        允许明文密码

mail_location = maildir:~/Maildir               设置邮件存储格式及位置

 

创建PAM认证文件

[root@www /]# vim /etc/pam.d/dovecot

     auth       required    pam_nologin.so

     auth       include     system-auth

     account    include     system-auth     

           session    include     system-auth

 

[root@www /]# /etc/init.d/dovecot start

Starting Dovecot.

[root@www /]# telnet www.benet.com 110

Trying 10.0.0.2...

Connected to www.benet.com.

Escape character is ‘^]‘.

+OK Dovecot ready.

user mail2                                         用户名

+OK

pass aptech                                        密码

+OK Logged in.

List                                                   邮件列表

+OK 1 messages:

1 427

.

retr 1                                                读取第一封邮件

+OK 427 octets

Return-Path: <mail1@benet.com>

X-Original-To: mail2@benet.com

Delivered-To: mail2@benet.com

Received: from www.benet.com (www.benet.com [10.0.0.2])

       by mail.benet.com (Postfix) with SMTP id 5624662052F

       for <mail2@benet.com>; Wed, 29 Jul 2015 08:26:32 +0800 (CST)

Subjec: A Test Mail

Message-Id: <20150729002651.5624662052F@mail.benet.com>

Date: Wed, 29 Jul 2015 08:26:32 +0800 (CST)

From: mail1@benet.com

 

T323-Y2                                           邮件内容

.

quit

+OK Logging out.

Connection closed by foreign host.

 

 

 

第三阶段

设置SMTP认证服务

[root@www ~]# vim /usr/lib64/sasl2/smtpd.conf

pwcheck_method:saslauth

[root@www ~]# /etc/init.d/saslauthd start

Starting saslauthd:                                        [  OK  ]

[root@www ~]# chkconfig --level 35 saslauthd on

修改main.conf配置文件,添加SMTP认证相关配置参数,并重新加载配置

[root@www ~]# vim /etc/postfix/main.cf

smtpd_sasl_auth_enable = yes

smtpd_sasl_security_options = noanonymous

mynetworks = 127.0.0.1

smtpd_recipient_restrictions =

 permit_mynetworks,

 permit_sasl_authenticated,

       reject_unauth_destination

[root@www ~]# postfix reload

postfix/postfix-script: refreshing the Postfix mail system

测试SMTP发信认证

认证时需要用户口令,加密的字串符编码格式为BASE64

获取密码:printf "zhangsan" | openssl base64   (用户名zhangsan)

                         printf "aptech" | openssl base64  (密码aptech)

 

[root@www ~]# telnet www.benet.com 25

Trying 10.0.0.2...

Connected to www.benet.com.

Escape character is ‘^]‘.

220 mail.benet.com ESMTP Postfix

EHLO www.benet.com

250-mail.benet.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH PLAIN LOGIN CRAM-MD5 DIGEST-MD5

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

AUTH LOGIN   

334 VXNlcm5hbWU6

bWFpbDE=

334 UGFzc3dvcmQ6

YXB0ZWNo

235 2.7.0 Authentication successful

MAIL FROM:mail1@benet.com

250 2.1.0 Ok

RCPT TO:mail2@benet.com

250 2.1.5 Ok

DATA

354 End data with <CR><LF>.<CR><LF>

Postfix     

.

250 2.0.0 Ok: queued as B0B69620537

QUIT

221 2.0.0 Bye

Connection closed by foreign host.

 

Postfix邮件系统

标签:

原文地址:http://www.cnblogs.com/baishuchao/p/5737809.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!