Postfix邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Postfix邮件相关的知识,希望对你有一定的参考价值。
Postfix
Postfix
邮件服务器概述
邮件服务器的原理
早期邮件发送过程
近期邮件发送过程
详细邮件发送过程
Postfix配置文件解析
邮件服务端配置和客户端使用
基于软件客户端(C/S)
基于软件Web(B/S)
1.DNS服务器添加域到区域文件
2.Postfix服务器安装并配置网站,数据库等
3.配置postfix支持虚拟域
4.配置MRA(dovecot)
5.配置Web界面
6.启动httpd,测试界面
邮件服务器概述
邮件服务器概念
电子邮件服务器是处理邮件交换的软硬件设施的总称,包括电子邮件程序、电子邮件箱等。他是为用户提供基于E-mail服务的电子邮件系统,人们通过访问服务器实现邮件的交换。常见的邮件服务器:
Linux:Sendmail、Qmail、Postfix、Zmailer
Exchange、Notes/Domino
Coremail、U-Mail
邮件系统角色
MUA(邮件用户代理)
MTA(邮件传输代理)
MDA(邮件分发代理)
MRA(邮件检索代理):替用户收取邮件
邮件应用协议
SMTP,简单邮件传输协议,TCP 25端口(发邮件)
SMTPS SMTP-over-ssl 加密时使用TCP 465端口
POP3,第三版有据协议,TCP 110端口(收邮件)
POP3S 加密时使用995端口
IMAP4,第四版互联网消息访问协议,TCP 143端口(收邮件)
IMAP4S TCP 993端口
邮件服务器的原理
早期邮件发送过程
早期邮件发送,客户端是发送端也是接受端,即充当客户端也充当服务端
客户端进程:SMTP
服务端进程:SMTPD
上图中,client-1通过SMTP服务向client-2连接SMTPD服务端口,client-2的SMTPD端口做出回应。这时client-1才向client-2发送邮件。发送过程中,client-2的SMTPD服务会检查这封邮件是发送给我的本机还是其他客户端。如果是本机,就在本机打开一个MDA(邮件分发代理),保存在本地的邮件目录(dir)中。如果是其他主机(比如[email protected]),SMTPD服务会转发给QQMile-server服务器,由QQMile-server继续处理。
近期邮件发送过程
早期邮件发送有一个弊端,客户端同时充当服务器的角色,一台客户端发送到另一台客户端的信件必须保证对方在线,负责邮件发送不出去。为解决这个问题,后期邮件发送将服务端和客户端分开。
客户端通过MUA(邮件用户代理)将邮件发送到服务器MTA(邮件传输代理),这时服务器会判断,这封邮件是不是发送到本域的用户还是发送到其他域的用户。如果是本域的用户,服务器会通过MDA(邮件分发代理)将邮件存放到自己的MailBox;如果不是本域的用户,服务器会通过MTA(邮件传输代理)转发至其他域的服务器。
当收邮件的客户端上线时,,客户端会通过服务器的MRA(邮件检索代理)去服务器检索有没有发送给自己的邮件。有的话MRA会将邮件发送给客户端。
详细邮件发送过程
客户端软件(Outlook)
客户端发送信件,POSTFIX调用Cyrus-SASL函数库模块,但是Cyrus-SASL函数库不能直接调用数据库,它会间接调用Courier-authlib函数库做发信认证,通过调用数据库来判断发信用户是不是本域用户。之后MTA(邮件传输代理)判断是发送到本域还是发送到外域。SASL simple authentication secure layer 简单认证安全层
浏览器Web端
浏览器可以直接访问数据库,所以
Postfix配置文件解析
queue_directory = /var/spool/postfix <=="邮件队列的位置,声明邮件过多的时候,邮件应该存放在哪个目录里" command_directory = /usr/sbin <=="命令目录" daemon_directory = /usr/libexec/postfix <==="程序目录,就是邮件各个组件存放的位置" data_directory = /var/lib/postfix <==="数据目录位置" mail_owner = postfix <==="邮件服务端属主名称,postfix运行身份" myhostname = mail.xxx.com <===="这个选项默认关闭,需要开启。指定邮件服务器的主机名,发送邮件可以使用 用户名@mail.xxx.com 也可以使用 用户名@xxx.com" mydomain = xxx.com <=="默认关闭,请开启。邮件域," # SENDING MAIL <==="发邮件的设置"#myorigin = $myhostname <==="这两个选项指定那些用户可以发送出邮件,默认关闭,请开启"#myorigin = $mydomain <==="作用是只有$mydomain和$myhostname变量后所跟的域名才能发送邮件" # RECEIVING MAIL <==="收邮件的设置"inet_interfaces = all <==="支持的IP地址或域名,默认关闭,请开启"#inet_interfaces = $myhostname#inet_interfaces = $myhostname, localhostinet_interfaces = localhost inet_protocols = all <=="支持的网络协议,有IPv4和IPv6" mydestination = $myhostname, localhost.$mydomain, localhost <==="$mydestination允许哪些邮件域给我本机发邮件,允许接收邮件的用户的邮件域"#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain <==="用这个比较全,这个好"#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,# mail.$mydomain, www.$mydomain, ftp.$mydomain unknown_local_recipient_reject_code = 550 <===="对于未知域所返回的错误代码" #alias_maps = dbm:/etc/aliases <===="做邮件转发的别名数据库文件位置"alias_maps = hash:/etc/aliases#alias_maps = hash:/etc/aliases, nis:mail.aliases#alias_maps = netinfo:/aliases #alias_database = dbm:/etc/aliases#alias_database = dbm:/etc/mail/aliasesalias_database = hash:/etc/aliases <==="定义一个组,给这个组内所有成员发信,别名数据库文件"#alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases # DELIVERY TO MAILBOX <==="邮件默认存放位置"#home_mailbox = Mailbox #home_mailbox = Maildir/ <=="默认没有开启,请开启,开这个。" debug_peer_level = 2 <===="错误日志的级别" debugger_command = <==="检测错误的命令的位置" PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5 sendmail_path = /usr/sbin/sendmail.postfix <==="sendmail 程序的位置" newaliases_path = /usr/bin/newaliases.postfix <==="重建别名的命令的位置" mailq_path = /usr/bin/mailq.postfix <==="邮件中mailq命令的位置" setgid_group = postdrop <==="默认存放邮件的丢弃组" html_directory = no manpage_directory = /usr/share/man <==="man手册位置" sample_directory = /usr/share/doc/postfix-2.6.6/samples <==="模本文件存放位置" readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES <==="帮助文档存放位置"
必须更改或开启的选项
myhostname 邮件服务器主机名
mydomain 邮件域
myorigin 允许发送邮件的用户的邮件域
mydestination 允许接收邮件的用户的邮件域
inet_interfaces = all 允许哪些IP来访问我的服务器
home_mailbox 邮件存放位置
邮件服务端配置和客户端使用
基于软件客户端(C/S)
安装DNS
[[email protected] ~]# yum -y install bind <==="安装DNS服务"[[email protected] ~]# vim /etc/named.conf <==="配置DNS"[[email protected] ~]# cd /etc[[email protected] etc]# cp -r named.rfc1912.zones named.rfc1912.zones.bak <=="拷贝一份DNS区域文件"[[email protected] etc]# vim named.rfc1912.zones <==="配置区域文件"[[email protected] etc]# cd /var/named/[[email protected] named]# cp -p named.lcoalshost xxx.localhost <==="拷贝数据文件"[[email protected] named]# vim xxx.localhost <==="修改数据文件" $TTL [email protected] IN SOA xxx.com. rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS dns.xxx.com. MX 3 mail.xdl.com. <=="设置优先级,数字越小,优先级越高"dns A 192.168.117.xxxmail A 192.168.117.xxxwww A 192.168.117.xxx[[email protected] ~]# /etc/init.d/named start <==="开启DNS"[[email protected] ~]# nslookup <==="检测DNS"
邮件服务端配置
[[email protected] ~]# vim /ets/system/network-scripts/ifcfg-eth0 <==="指定DNS"[[email protected] ~]# cd /etc/postfix/[[email protected] postfix]# lsaccess generic main.cf relocated virtualcanonical header_checks master.cf transport <==="main.cf和master.cf都是主配置文件"[[email protected] postfix]# vim main.cf <==="修改main.cf"[[email protected] postfix]# service postfix start <==="打开邮件服务"
发送邮件
[[email protected] ~]# useradd user1 <=="创建发送邮件的用户"[[email protected] ~]# echo "123456" | passwd --stdin user1[[email protected] ~]# useradd user2 <=="创建发送邮件的用户"[[email protected] ~]# echo "123456" | passwd --stdin user2[[email protected] ~]# yum -y insrall telnet <==="发邮件需要用到Telnet"[[email protected] ~]# telnet localhost 25 <==="连接25端口"helo mail.xxx.com <==="声明当前邮件服务器的名称"mail from: 用户名@xxx.com <==="声明邮件由谁来发 from,别写错!!!"rcpt to: 用户名@xxx.com <==="声明邮件谁来接收"data <==="声明要写入正文"XXXXXXXXXX <==="正文内容". <===="重起一行,以 . 作为结束"quit <==="退出"[[email protected] ~]# cd /收件人家目录/Maildir/ <=="邮件存储在这个目录"[[email protected] Maildir]# lscur new tmp[[email protected] Maildir]# cd new[[email protected] new]# ls1461968794.Vfd00I436a6M677084.renkeju.com[[email protected] new]# cat 1461968794.Vfd00I436a6M677084.renkeju.com Return-Path: <[email protected]>X-Original-To: [email protected]: [email protected]: from mail.renkeju.com (localhost [IPv6:::1]) by mail.renkeju.com (Postfix) with SMTP id 37EB129C for <[email protected]>; Sat, 30 Apr 2016 06:25:13 +0800 (CST)Message-Id: <[email protected]>Date: Sat, 30 Apr 2016 06:25:13 +0800 (CST)From: [email protected]: undisclosed-recipients:; test[[email protected] ~]# yum -y install dovecot* <==="安装收信认证软件(MRA):dovecot"[[email protected] ~]# service dovecot start[[email protected] ~]# netstat -anpt | grep dovecot[[email protected] ~]# telnet localhost 110user 用户名pass 密码list 显示邮件列表retr 输入邮件编号,读取邮件quit 退出
基于软件Web(B/S)
1.DNS服务器添加域到区域文件
[[email protected] ~]# vim /etc/named.rfc1912.zones zone "renkeju.com" IN { type master; file "renkeju.localhost"; allow-update { none; };}; zone "extmail.org" IN { type master; file "extmail.org"; allow-update { none; };}; zone "extmail.com" IN { type master; file "extmail.com"; allow-update { none; };};[[email protected] ~]# cd /var/named/[[email protected] named]# cp -p renkeju.localhost extmail.com[[email protected] named]# cp -p renkeju.localhost extmail.org[[email protected] named]# vim extmail.com $TTL [email protected] IN SOA extmail.com. rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS dns.extmail.com. MX 3 mail.extmail.com.dns A 192.168.117.135www A 192.168.117.133mail A 192.168.117.134 [[email protected] named]# vim extmail.org $TTL [email protected] IN SOA extmail.org. rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS dns.extmail.org. MX 3 mail.extmail.org.dns A 192.168.117.135www A 192.168.117.133mail A 192.168.117.134[[email protected] named]# nslookup
2.Postfix服务器安装并配置网站,数据库等
[[email protected] named]# yum -y install httpd mysql mysql-server gcc* mailx <=="安装软件,mailx邮件管理工具"[[email protected] named]# service mysqld start <==="开启数据库"[[email protected] named]# mkdir /var/www/extsuite <==="提前创建一个目录,用来存放解压文件"[[email protected] ~]# cd /usr/src/EXMAIL[[email protected] EXMAIL]# tar -zxf extman-1.1.tar.gz[[email protected] EXMAIL]# tar -zxf extmail-1.2.tar.gz[[email protected] EXMAIL]# mv extmail-1.2 /var/www/extsuite/extmail <=="访问时的前端服务器"[[email protected] EXMAIL]# mv extman-1.1 /var/www/extsuite/extman <==="管理后端的工具平台"[[email protected]renkeju EXMAIL]# cd /var/www/extsuite/extman/docs/[[email protected] docs]# vim init.sql <==="修改[email protected]的密码"...省略...INSERT INTO `manager` VALUES (‘[email protected]‘,‘$1$BrT9qxfB$Ha81Mb5YVV6rNKNN5jmtj1‘,‘admin‘,‘root‘,‘Super User‘,‘my question‘,‘my answer‘,‘0‘,‘2007-02-14 15:10:04‘,‘2010-11-08‘,1); [[email protected] docs]# mysql < extmail.sql <==="导入extmail自带数据库,顺序不能颠倒"[[email protected] docs]# mysql < init.sql <==="导入extmail的测试账户"
3.配置postfix支持虚拟域
[[email protected] docs]# cp mysql_virtual_alias_maps.cf /etc/postfix/[[email protected] docs]# cp mysql_virtual_domains_maps.cf /etc/postfix/[[email protected] docs]# cp mysql_virtual_mailbox_maps.cf /etc/postfix/ <==="拷贝模板文件"[[email protected] docs]# useradd -u 600 vmail <==="指定虚拟用户的用户名和UID"#下面这些选项也可以在/etc/postfix/main.cf配置文件中来修改[[email protected] docs]# postconf -e inet_interfaces=all <==="就这个选项是默认有的,其他都需要手动添加"[[email protected] docs]# postconf -e virtual_mailbox_base=/home/vmail/[[email protected] docs]# postconf -e virtual_uid_maps=static:600[[email protected] docs]# postconf -e virtual_gid_maps=static:600#设置postfix读取模板文件[[email protected] docs]# postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql_virtual_alias_maps.cf[[email protected] docs]# postconf -e virtual_mailbox_domains=mysql:/etc/postfix/mysql_virtual_domains_maps.cf[[email protected] docs]# postconf -e virtual_mailbox_maps=mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf[[email protected] docs]# /etc/init.d/postfix restart <==="重启postfix,查看是否成功!"#测试一下[[email protected] docs]# echo "hi " | mail -s test [email protected][[email protected] ~]# cd /home/vmail/#如果你看不到文档,肯定/etc/postfix/main.cf配置文件参数写错了。重启mysqld(重要)和postfix服务。[[email protected] vmail]# lsextmail.org[[email protected] vmail]# cd extmail.org/[[email protected] extmail.org]# lspostmaster[[email protected] extmail.org]# cd postmaster/[[email protected] postmaster]# lsMaildir[[email protected] postmaster]# cd Maildir/[[email protected] Maildir]# lscur new tmp[[email protected] Maildir]# cd new/[[email protected] new]# ls1461958139.Vfd00I26025M495183.renkeju.com[[email protected] new]# cat 1461958139.Vfd00I26025M495183.renkeju.com Return-Path: <[email protected]>X-Original-To: [email protected]: [email protected]: by renkeju.com (Postfix, from userid 0) id 66BDE26020; Sat, 30 Apr 2016 03:28:59 +0800 (CST)Date: Sat, 30 Apr 2016 03:28:59 +0800To: [email protected]: testUser-Agent: Heirloom mailx 12.4 7/29/08MIME-Version: 1.0Content-Type: text/plain; charset=us-asciiContent-Transfer-Encoding: 7bitMessage-Id: <[email protected]>From: [email protected] (root) hi
4.配置MRA(dovecot)
[[email protected] new]# yum -y install dovecot-mysql dovecot telnet -y[[email protected] new]# cd /etc/dovecot/conf.d/[[email protected] conf.d]# vim 10-mail.conf...省略...# %u - username# %n - user part in [email protected], same as %u if there‘s no domain# %d - domain part in [email protected], empty if there‘s no domain# %h - home directorymail_location = maildir:/home/vmail/%d/%n/Maildir "24行" "邮件收取配置,这里采用maildir形式"first_valid_uid = 600 "167行" "设置存放邮件默认用户的UID从多少开始。 所有配置选项都必须顶头写,不然不认。" [[email protected] conf.d]# vim 10-auth.conf!include auth-sql.conf.ext "去掉注释" "120行"[[email protected] dovecot]# cp /usr/share/doc/dovecot-2.0.9/example-config/dovecot-sql.conf.ext /etc/dovecot/ [[email protected] dovecot]# vim dovecot-sql.conf.extdriver = mysql "29行"connect = host=localhost dbname=extmail user=extmail password=extmail "63行"default_pass_scheme = MD5 "73行"password_query = \ "102行" SELECT username, domain, password \ FROM mailbox WHERE username = ‘%u‘ AND domain = ‘%d‘user_query = SELECT maildir, 600 AS uid, 600 AS gid FROM mailbox WHERE username = ‘%u‘ "120行"#启动dovecot测试[[email protected] dovecot]# /etc/init.d/dovecot start[[email protected] dovecot]# telnet localhost 110Trying ::1...Connected to localhost.Escape character is ‘^]‘.+OK Dovecot ready.user [email protected]+OKpass extmail+OK Logged in.list+OK 1 messages:1 520.quit+OK Logging out.Connection closed by foreign host.
5.配置Web界面
[[email protected] dovecot]# vim /etc/httpd/conf/httpd.conf NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /var/www/html ServerName www.example.com</VirtualHost> <VirtualHost *:80> DocumentRoot /var/www/extsuite/extmail/html/ ServerName mail.extmail.org ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi Alias /extmail /var/www/extsuite/extmail/html ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi Alias /extman /var/www/extsuite/extman/html SuexecUserGroup vmail vmail</VirtualHost> [[email protected] dovecot]# cd /var/www/extsuite/extmail/[[email protected] extmail]# chown -R vmail:vmail cgi/[[email protected] extmail]# cp webmail.cf.default webmail.cf[[email protected] extmail]# vim webmail.cfSYS_MAILDIR_BASE = /home/vmail "127行"SYS_CRYPT_TYPE = plain "136行"SYS_MYSQL_USER = extmail "139行"SYS_MYSQL_PASS = extmail[[email protected] extmail]# cd /var/www/extsuite/extman/[[email protected] extman]# chown -R vmail:vmail cgi/[[email protected] extman]# cp webman.cf.default webman.cf[[email protected] extman]# vim webman.cfSYS_MAILDIR_BASE = /home/vmail "12行"SYS_SESS_DIR = /tmp/ "18行"SYS_CAPTCHA_LEN = 4 "27行"SYS_CRYPT_TYPE = plain "124行"
6.启动httpd,测试界面
如图一:
[[email protected] extman]# yum -y install *CGi
如图二:
[[email protected] extman]# cd /usr/src/[[email protected] src]# tar -zxf Unix-Syslog-1.1.tar.gz[[email protected] src]# cd Makefile.PL[[email protected] Makefile.PL]# make test[[email protected] Makefile.PL]# make install
在新用户注册时,出现验证码显示不正常:
如图三:
[[email protected] Makefile.PL]# yum install -y perl-GD
本文出自 “linu_服务篇” 博客,请务必保留此出处http://zhaolu.blog.51cto.com/3719883/1775782
以上是关于Postfix邮件的主要内容,如果未能解决你的问题,请参考以下文章