一、邮件服务器系统原理 

邮件系统中的角色

MUAMail User Agent ,邮件用户代理

MTAMail Transfer Agent ,邮件传输代理

MDAMail Delivery Agent ,邮件投递代理

邮件协议

邮件发送协议SMTP

Simple Mail Transfer Protocol ,简单邮件传输协议

邮件收取协议

POP3 Post Office Protocol V3,邮局协议第3

IMAP4 Internet Message Access Protocol  V4,因特网消息访问协议第4

 

二、Postfix邮件系统的架构 

 

三、安装及配置Postfix邮件服务 

1,建立测试用户

2,安装postfix

yum -y install postfix wireshark

3,关闭sendmail

service sendmail stop

chkconfig sendmail on

 

alternatives --config mta      选择使用哪个MTA来传送邮件

 

4,开始启动postfix

[root@server1 ~]#vi  /etc/postfix/main.cf

myhostname = station7.example.com

inet_interfaces = all

记住要注释掉:inet_interfaces = localhost

mynetworks = 192.168.0.0/24 127.0.0.0/8  标注可以使用该邮件服务器的地址范围。

 

[root@server1 ~]#service postfix restart

[root@server1 ~]#chkconfig postfix on

 

四、Postfix主要配置文件 

主配置文件:/etc/postfix/main.cf

[root@server1 ~]#grep  -v  "^#" /etc/postfix/main.cf

queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = /usr/libexec/postfix

mail_owner = postfix

myhostname = server2.example.com

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost

unknown_local_recipient_reject_code = 550

mynetworks = 192.168.2.0/24, 127.0.0.0/8

alias_maps = hash:/etc/aliases

alias_database = hash:/etc/aliases

debug_peer_level = 2

debugger_command =

         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin

         xxgdb $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail.postfix

newaliases_path = /usr/bin/newaliases.postfix

mailq_path = /usr/bin/mailq.postfix

setgid_group = postdrop

html_directory = no

manpage_directory = /usr/share/man

sample_directory = /usr/share/doc/postfix-2.3.3/samples

readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES

 

五、安装及配置pop3服务

Dovecot Setup

1,install

[root@server1 ~]#yum -y install dovecot

2,配置时间和服务器一致,最好使用NTP,也可以使用date -s 年月日或date -s 时:分:秒

3,配置

[root@server1 ~]#vi /etc/dovecot.conf

#protocols = pop3 imap imaps pop3s

protocols =pop3 imap imaps pop3s

 

[root@server1 ~]#service dovecot start

[root@server1 ~]#chkconfig dovecot on

[root@server1 ~]#service iptables stop

测试:

[root@server1 ~]#echo "thist is a test "|mail -s "hello" [email protected]

[root@server1 ~]#mutt -f pops://[email protected]

 

六、使用cyrus-sasl增加SMTP认证 

SMTP认证的配置
安装cyrus-sasl
1
、确认cyrus-sasl是否安装了
[root@server1 ~]# rpm -qa|grep cyrus
cyrus-sasl-plain-2.1.22-4
cyrus-sasl-lib-2.1.22-4
cyrus-sasl-2.1.22-4

Cyrus-SASL V2
的密码验证机制
[root@server1 ~]# saslauthd -v
saslauthd 2.1.22
authentication mechanisms: getpwent kerberos5 pam rimap shadow ldap
我们准备用的是shadow的密码验证机制。

[root@server1 ~]#vi /etc/sysconfig/saslauthd
MECH=shadow
启动sasldaemon并测试:
[root@server1 ~]# service saslauthd start

开启saslselinux布尔值

[root@server1 ~]#setenfoce      0
[root@server1 ~]# /usr/sbin/testsaslauthd -u
帐号 -p '密码'
0: OK "Success."   =>
帐号验证成功了
[root@server1 ~]# chkconfig saslauthd on

设置postfix启用SMTP认证
[root@server1 ~]# vi /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain= ''
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,
           reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous

 



wq!
保存

此外,由于当postfix要使用SMTP认证时,会读取/usr/lib/sasl2/smtpd.conf文件的内容以确定所采用的认证方式,所以必须保证/usr/lib/sasl2/smtpd.conf文件的内容是:
pwcheck_method: saslauthd

 

测试:

没有使用smtp验证时

[root@server1 ~]# telnet 192.168.2.253 25

Trying 192.168.2.253...

Connected to server2.example.com (192.168.2.253).

Escape character is '^]'.

220 server2.example.com ESMTP Postfix

ehlo localhost

250-server2.example.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

 

使用了smtp验证时:

[root@server1 ~]# telnet 192.168.2.253 25

Trying 192.168.2.253...

Connected to server2.example.com (192.168.2.253).

Escape character is '^]'.

220 server2.example.com ESMTP Postfix

ehlo localhost

250-server2.example.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH LOGIN PLAIN

250-AUTH=LOGIN PLAIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

 

 

七、使用telnet测试smtppop3服务

使用telnet发送邮件

[root@server2 ~]# telnet 192.168.2.253 25

Trying 192.168.2.253...

Connected to server1.example.com (192.168.2.253).

Escape character is '^]'.

220 server1.example.com ESMTP Postfix

helo example.com

250 server1.example.com

mail from:

250 2.1.0 Ok

rcpt to:

250 2.1.5 Ok

data

354 End data with .

hello!1211311

this is hello for ann

.

250 2.0.0 Ok: queued as EBE88F06C2

quit

221 2.0.0 Bye

Connection closed by foreign host.

[root@server2 ~]# mailq

Mail queue is empty

[root@server2 ~]# su - ann

[ann@server2 ~]$ mail

Mail version 8.1 6/6/93.  Type ? for help.

"/var/spool/mail/ann": 1 message 1 new

>N  1 [email protected]  Wed Aug 12 06:43  15/568 

& q

Held 1 message in /var/spool/mail/ann

 

使用telnet收邮件

[root@server2 ~]# telnet 192.168.2.253 110

Trying 192.168.2.253...

Connected to server1.example.com (192.168.2.253).

Escape character is '^]'.

+OK Dovecot ready.

user ann

+OK

pass ann

+OK Logged in.

quit

+OK Logging out.

Connection closed by foreign host.

 

八、设置邮件别名和群组  [★]

邮件用户别名

[root@server1 ~]#vi  /etc/aliases

添加一行:

local        mate,tony

localhost:           mate

 

添加好以后使用命令:newaliases更新别名数据库。

发送给local的邮件都转发给matetony

发送给localhost的邮件都转发给mate

 

 

九、设置邮箱空间大小和邮件大小限制  [★]

主配置文件参数:

#最大smtp并发进程数
default_process_limit = 1024
# 本地同时同址分发限制
local_destination_concurrency_limit = 50
# 同时同址分发限制
default_destination_concurrency_limit = 50
# 反垃圾邮件组织过滤
maps_rbl_domains = blackholes.mail-abuse.org
# 最大邮件的长度
message_size_limit = 52428800
# 最大邮箱大小
mailbox_size_limit = 524288000
# 弹回最大邮件的大小
bounce_size_limit = 52428800

 

十、安装及配置SquirrelMail系统 

安装:

[root@server2 ~]#yum  -y  install   squirrelmail

[root@server2 ~]#/usr/share/squirrelmail/config/conf.pl

 

输入d,然后输入cyrus(指定IMAP服务器类型)

输入2. 选择Server Settings然后输入1修改Domainexample.com

                                  3修改Sendmail or SMTPSMTP

输入4. 选择General Options然后输入5修改Usernames in Lowercase : true

输入10 选择Languages然后输入1修改Default Language : zh_CN

最后输入s保存以上修改,再输入q退出(修改的文件同时保存在/etc/squirrelmail/config.php/usr/share/squirrelmail/config/config.php

 

浏览器中输入http://服务器域名或IP/webmail.打开登陆页面

 输入用户名和密码(默认可以用系统存在的用户名)

 

squirrelmail附件大小的设置方法
 
今天终于把squirrelmail的附件大小限制搞定了。主要方法是:修改php.ini
 cd /etc/php5/apache2/
 vi /php.ini
 max_execution_time=30 ;//
改为600(增加处理脚本的时间限制)
 max_input_time=600 ;//
最大输出时间600s
 memory_limit=8M ;//
改为100M(这样才能发送100M以下的附件)
 register_global=on ;//
个人认为没必要打开
 post_max_size=2M ;//php
可接收的post的大小
 file_uploads=on ;//
允许上传文件
 upload_max_filesize=2M ;//
改为100M
 session_auto_start=1 ;//seession
自动启动(我没改)
 
参考技术信息:
 
修改SquirrelMail 附件的大小到10M
 
如果您要修改SquirrelMail 附件的大小,需要直接修改 /etc/php5/apache2/php.ini 文件:
 memory_limit = 40M ; //
改为40M (这样才能发10M的附件)
 post_max_size = 10M ; //php
可接受的 post 方法大小 10M
 upload_max_filesize = 10M ; //
最大上载文件10M
 
如果使用Postfix 作为后台邮件服务器,还需要修改main.cf
 message_size_limit = 14336000 (
附件大小,14M,实际为10M的文件)
 mailbox_limit = 102400000
(邮箱空间100M
 create_maildirsize = yes
 mailbox_extended = yes