前言
现有需求要使用postfix服务配置一台邮箱服务器。(测试环境)
要求:
- 用户邮箱限额。
- 用户发件大小限额。
- 支持sasl验证。
- 支持收件。(使用dovecot)
配置过程
首先配置软件安装源,这是必不可少的。
配置发件服务器
在CentOS6.5的环境下,默认已经安装上了postfix服务,所以就不进行安装了。
配置postfix
- 由于postfix仅需要配置 /etc/postfix/main.cf,所以相对其他服务较为简单。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | [root@centos-linux ~]# vi /etc/postfix/main.cf # 设置域名 78 # The mydomain parameter specifies the local internet domain name. 79 # The default is to use $myhostname minus the first component. 80 # $mydomain is used as a default value for many other configuration 81 # parameters. 82 # 83 mydomain = test.com # 设置发件后缀 93 # 94 # For the sake of consistency between sender and recipient addresses, 95 # myorigin also specifies the default domain name that is appended 96 # to recipient addresses that have no @domain part. 97 # 98 #myorigin = $myhostname 99 myorigin = $mydomain # 监听所有端口 110 # 111 # Note: you need to stop/start Postfix when this parameter changes. 112 # 113 inet_interfaces = all 114 #inet_interfaces = $myhostname 115 #inet_interfaces = $myhostname, localhost 116 #inet_interfaces = localhost (注意屏蔽该行,作用:只监听回环端口) # 设置允许发件的域名 161 # 162 # See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS". 163 # 164 mydestination = $mydomain # 设置监听的端口 260 # You can also specify the absolute pathname of a pattern file instead 261 # of listing the patterns here. Specify type:table for table-based lookups 262 # (the value on the table right-hand side is not used). 263 # 264 mynetworks = 0.0.0.0/0 # 设置发件存储位置 412 # 413 # The home_mailbox parameter specifies the optional pathname of a 414 # mailbox file relative to a user's home directory. The default 415 # mailbox file is /var/spool/mail/user or /var/mail/user. Specify 416 # "Maildir/" for qmail-style delivery (the / is required). 417 # 418 #home_mailbox = Mailbox 419 home_mailbox = Maildir/ # 邮箱(20MB)以及邮件(5MB)大小限制 678 message_size_limit = 5242880 679 mailbox_size_limit = 20971520 # 配置sasl验证 680 smtpd_sasl_enable = yes |
- sasl验证还要对saslauthd服务进行配置,默认情况下,sasl是不支持pam模式认证的。
1 2 3 4 5 6 7 8 9 10 11 12 | [root@centos-linux ~]# vi /etc/sysconfig/saslauthd 5 # Mechanism to use when checking passwords. Run "saslauthd -v" to get a list 6 # of which mechanism your installation was compiled with the ablity to use. 7 MECH=shadow # 配置完之后开启服务,并设置开机启动 [root@centos-linux ~]# chkconfig saslauthd on [root@centos-linux ~]# service saslauthd start 正在启动 saslauthd: [确定] [root@centos-linux ~]# service saslauthd status saslauthd (pid 1636) 正在运行... |
配置收件服务器
由于CentOS6.5的镜像软件源提供了dovecot,所以安装dovecot服务即可实现收件功能。
安装dovecot
1 2 3 4 5 6 7 8 | [root@centos-linux ~]# yum -y install dovecot ...忽略无用内容... Installed: dovecot.x86_64 1:2.0.9-7.el6 Complete! |
配置dovecot
- 开启对收件协议的支持(去掉注释符)
1 2 3 4 | [root@centos-linux ~]# vi /etc/dovecot/dovecot.conf 19 # Protocols we want to be serving. 20 protocols = imap pop3 lmtp |
- 关闭ssl协议(测试环境就不管安全性啦)
1 2 3 4 5 6 7 8 | [root@centos-linux ~]# vi /etc/dovecot/conf.d/10-ssl.conf 1 ## 2 ## SSL settings 3 ## 4 5 # SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt> 6 ssl = no |
- 开启明文验证
1 2 3 4 5 6 7 8 9 10 11 | [root@centos-linux ~]# vi /etc/dovecot/conf.d/10-auth.conf 1 ## 2 ## Authentication processes 3 ## 4 5 # Disable LOGIN command and all other plaintext authentications unless 6 # SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP 7 # matches the local IP (ie. you're connecting from the same computer), the 8 # connection is considered secure and plaintext authentication is allowed. 9 disable_plaintext_auth = no |
- 设置邮箱存放位置
- 由于24行的样本位置即是postfix的默认发件位置,所以解除该行屏蔽即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 | [root@centos-linux ~]# vi /etc/dovecot/conf.d/10-mail.conf 21 # 22 # See doc/wiki/Variables.txt for full list. Some examples: 23 # 24 mail_location = maildir:~/Maildir 25 # mail_location = mbox:~/mail:INBOX=/var/mail/%u 26 # mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n 27 # 28 # <doc/wiki/MailLocation.txt> 29 # 30 #mail_location = 31 |
好了,做完以上操作后,基本上收件服务器的配置就完成了。
然后配置下开机启动,以及开启服务。
1 2 3 4 5 6 | [root@centos-linux ~]# chkconfig dovecot on [root@centos-linux ~]# service dovecot start 正在启动 Dovecot Imap: [确定] [root@centos-linux ~]# service dovecot status dovecot (pid 1556) 正在运行... [root@centos-linux ~]# |
配置测试环境
- 首先当然是添加用户了。
1 2 3 4 5 6 7 8 | [root@centos-linux ~]# useradd mail1 [root@centos-linux ~]# echo 321|passwd --stdin mail1 更改用户 mail1 的密码 。 passwd: 所有的身份验证令牌已经成功更新。 [root@centos-linux ~]# useradd mail2 [root@centos-linux ~]# echo 321|passwd --stdin mail2 更改用户 mail2 的密码 。 passwd: 所有的身份验证令牌已经成功更新。 |
- 由于是测试环境,也没有进行dns服务器的配置,所以使用hosts模拟域名解析。
1 2 3 4 5 | [root@centos-linux ~]# vi /etc/hosts 1 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 2 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 3 10.211.55.4 test.com |
正常情况下,到这一步已经全部配置好了,已经可以进行发件测试了。(注意关闭防火墙)
- 如图,发送成功,想必看到这套参数的人,都明白我做的是什么了,終わり。
原文链接:点击打开链接