天天看点

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

                                            Postfix邮件系统

1、电子邮件系统基础

(1)邮件系统角色、邮件协议

①邮件系统的角色

1)MTA(Mail Transfer Agent,邮件传输代理):邮件服务器软件

2)MUA(Mail User Agent,邮件用户代理):邮件客户端

3)MDA(Mail Delivery Agent,邮件分发代理):服务器邮件分发

②邮件通信协议

1)SMTP(Simple Mail Transfer Protocol,简单邮件传输协议):用于发送和传输邮件。使用TCP协议25端口

2)POP(Post Office Protocol,邮局协议):用于从邮件服务器中收取邮件。目前最新版本为POP3,使用TCP协议110端口

3)IMAP(Internet Message Access Protocol,互联网消息访问协议):用于收取邮件。目前最新版本为IMAP4,与POP3相比,提供了更灵活和强大的邮件收取、管理功能。使用TCP协议143端口

4)只有电子邮件客户端和服务器同时支持SMTP和POP/IMAP协议,才能够实现完整的邮件发送和接收功能

③常见的邮件服务器软件

1)商业邮件系统

a.Excange:windows系统中最著名的邮件服务器软件

b.Notes/Domino:IBM公司出品的软件产品

2)开源邮件系统

a.Sendmail:运行于Linux/unix系统,稳定性较好,但安全性欠佳

b.Qmail:比Sendmail具有更好的执行效率,且配置、管理更方便

c.Postfix:由Wietse负责开发。投递效率、稳定性、服务性及安全性方面都有相当出色的表现

2、Postfix邮件服务基础

3、Postfix安装部署

(1)环境配置:

①hostname

②iptables

③selinux

④IPaddress

⑤Centos6中需卸载sendmail

⑥安装支持工具:cyrus*

⑦创建运行用户和组

1)group:postdrop、postfix

2)user:postfix -g postfix -G postdrop

(2)配置DNS服务器

(3)源码编译安装postfix

①make makefiles

(4)相关配置目录文件

①配置文件目录/etc/postfix

②服务程序目录/usr/libexec/postfix

③邮件队列目录/usr/spool/postfix

1)incoming:发来的邮件队列

2)active:正在投递的队列

3)deferred:延迟邮件队列

4)hold:阻止的邮件队列

5)corrupt:损坏的邮件队列

④管理程序目录/usr/sbin

1)postalias:设置别名数据库

2)postmap:检查语法错误

3)pstconf:打印配置参数设置后的值

a.-d:打印缺省值

b.-m:列出所有支持的查询表类型

4)postqueue:一般用户能够有限度的访问postfix队列

a.-p:显示信件队列

b.-f:全部清扫队列

⑤配置文件

1)/etc/postfix/master.cf:主程序配置文件

2)/etc/postfix/main.cf:服务的配置文件

3)postconf:检查当前有效配置

a.-n:查看非默认配置

b.-d:查看默认配置

(5)修改主配置文件main.cf

①muhostname=mail.luoxinli.top:主机名

②mydomain=luoxinli.top:管理域

③myorigin=$mydomian:访问的域

④inet_interfaces=all:允许所有人发送邮件

⑤mydestination=:允许投递的对象

⑥mail_location=maildir:邮件存放位置(宿主目录)

(6)测试

①发送邮件:

1)telnet mail.luoxinli.top 25

2)helo mail:luoxinli.top

3)mail frome:[email protected]

4)rcpt tp:[email protected]

5)data

6)正文

7).

8)quit

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

②查看邮件

1)cat home/mub/Maildir/new/…

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

4、搭建dovecot提供收信服务

(1)安装dovecot软件包

①yum install -y dovecot

(2)修改配置文件/etc/dovecot/dovecot.conf

①修改:protocols=imap pop3 lmtp

②修改:listen *

③修改:!include conf.d/10-auth.conf

④添加:ssl=no

⑤添加:disable_plaintext_auth=no

⑥添加:mail_location=maildir:~/Maildir

(3)启动服务dovecot

(4)收信验证:

①telnet mail.luoxinli.top 110

②user bmu

③pass 111111

④list:查看邮件

⑤retr 1:读取编号1的邮件

⑥quit:退出

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

5、outlokk收信验证

(1)配置outlook

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统
Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

(2)使用outlook发送邮件

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

(3)服务器验证收信

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

(4)切换lookout账号验证收信

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

6、发信认证配置

(1)编辑认证配置文件

①安装cyrus-sas文件:yum install -y cyrus-sasl*

②编辑配置文件/etc/sasl2/smtpd.conf

1)pwcheck_method: saslauthd

2)mech_list: plain login

3)log_leve: 3

③重启服务:saslauthd

(2)编辑postfix主配置文件/etc/postfix/main.cf

①添加smtpd_sasl_auth_enable=yes(开启认证)

②添加smtpd_sasl_security_options=noanonymous(不允许匿名发信)

③添加mynetworks=192.168.11.0/24(允许的网段,如果增加本机所在网段就会出现允许不验证也能向外域发信)

④smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination(允许本地域以及认证成功的发信,拒绝认证失败的发信)

⑤postfix check检查语法错误

⑥重启postfix服务

(3)测试普通发信验证

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

由于*******@qq.com未认证,所以拒绝访问,发送失败

(4)将邮件用户名和密码生成密文

①printf “mua” | openssl base64

②printf “111111” | openssl base64

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

(5)字符终端测试认证发信

①telnet mail.luoxinli.top 25

②ehlo mail.aa.top (注意是ehlo不是helo)

③auth login (认证登录)

④amFjaw== (密文用户名)

⑤MTIz (密文密码)

⑥mail from:[email protected]

⑦rcpt to:[email protected]

⑧data

⑨this is test 

⑩.

⑪quit

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

(6)outlook测试认证发信

①软件设置

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

②发送邮件

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

③收件

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

7、squirrelmail配置

(1)安装httpd、msql-server、php服务

①yum install -y httpd mysql-server php php-musql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash

(2)配置httpd主配置文件/etc/httpd/conf/httpd.conf

①ServerName mail.luoxinli.top

②DirectoryIndex index.htm index.php

(3)编辑PHP主配置文件/etc/php.ini

①date.timezone = PRC

(4)启动httpd、mysql服务

(5)编辑mysql数据安全配置

①mysql_secure_installation(首次直接回车进入设置)

②

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

1)首次直接回车进入

③

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

1)修改root用户密码,选y进行设置

④

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

1)选Y删除匿名用户

⑤

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

1)选n设置允许管理员远程登录

⑥

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

1)选Y删除测试数据库

(6)编辑mysql数据库

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

(7)下载squirrelmail

①http://www.squirrelmail.org/download.php

②squirrelmail-webmail-1.4.22.tar.gz

(8)将文件解压到/var/www/html/目录

①tar xzvf squirrelmail-webmail-1.4.22.tar.gz -C /var/www/html/

(9)创建默认配置文件(先进入/var/www/html/目录)

①mkdir attach

②chown -R apache:apache attach/  data/

③cp config/config_default.php config/config.php

(10)编辑配置文件config.php

①$domain = 'aa.com'; (域名)

②$imap_server_type = 'dovecot'; (服务类型)

③$data_dir = '/var/www/html/mail/data'; (数据目录)

④$attachment_dir = '/var/www/html/mail/attach/';(附件目录)

⑤$squirrelmail_default_language = 'zh_CN'; (默认语言环境)

⑥$default_charset = 'zh_CN.UTF-8'; //默认字符编码

⑦注意特殊字符,“$”与“;”不要漏掉

(11)验证

Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统
Linux网络服务与shell脚本——Postfix邮件服务器搭建                                            Postfix邮件系统

(12)易错点

①服务未启动(mysqld、httpd、dovecot)

②文件及目录权限(attach及data目录)

继续阅读