Postfix邮件服务器主要由cyrus-sasl、postfix、dovecot、postfixadmin、roundcubemail等5个组件组成。
在 linux 平台中,有许多邮件服务器可供选择,但目前使用最多的是 sendmail 服务器、postfix 服务器和Qmail 服务器。
◆ Sendmail 是一个很优秀的邮件服务软件。几乎所有 linux 的缺省配置中都内置了这个软件,只需要设置好操作系统,它就能立即运转起来。
◆ Postfix 是一个由 IBM 资助下由 Wietse Venema 负责开发的一个自由软件工程产物,它的目的就是为用户提供除 Sendmail 之外的邮件服务器选择。
◆ Qmail 是有 Dan Bernstein 开发的可以自由下载邮件服务器软件,其第一个 beta 版本 0.7 发布于 1996年 1 月 24 日。
(1)Postfix功能简介
◆ Postfix 邮件服务器是使用得十分广泛的邮件提交工具(MSP)。
◆ 在邮件模型中承担着 MTA 及 MDA 的作用。
◆ 支持多种类型的邮件地址寻址。
◆ 支持虚拟域及虚拟用户。
◆ 提供在投递失败后自动重发等多种错误应对策略。
(2)Postfix进程介绍
◆ 后台进程:postfix
◆ 安装包:postfix
◆ 所用端口:25(SMTP)
◆ 主配置文件:/etc/postfix/main.cf
◆ SMTP(Simple Mail Transfer Protocol)简单邮件传送协议。
◆ 定义邮件传送(明文传送)
◆ 基于 TCP 服务器的应用层。
◆ SMTP 协议使用 25 端口。
◆ 在安装 postfix 邮件服务器时,此协议有随之安装在系统中。
(1)POP3协议
◆ POP3:Post Office Protocol3/邮局协议第三版
◆ POP3 协议适用于不能时时在线的邮件用户。支持客户在服务器上租用信箱,然后利用 POP3 协议向服务器请求下载。
◆ 基于 TCP/IP 协议与客户端/服务端模型
◆ POP3 的认证与邮件传送都采用明文
◆ 使用 110 端口
(2)IMAP协议
◆ IMAP:Internet Message Access Protocol/英特网信息存取协议
◆ 另一种从邮件服务器上获取邮件的协议
◆ 与 POP3 相比,支持在下载邮件前先行下载邮件头以预览邮件的主题来源
◆ 基于 TCP/IP
◆ 使用 143 端口
cyrus-sasl(Simple Authentication Security Layer)简单认证安全层, SASL主要是用于SMTP认证。而cyrus-sasl在OS里面,saslauthd是其守护进程。
(1)安装cyrus-sasl包
[root@10-27-0-224 ~]# yum -y install cyrus-sasl -y
(2)版本查看
[root@10-27-0-224 ~]# saslauthd -v saslauthd 2.1.26 authentication mechanisms: getpwent kerberos5 pam rimap shadow ldap httpform
saslauthd是认证服务cyrus-sasl的守护进程,所以我们就可以通过saslauthd查看cyrus-sasl的版本。
(3)修改cyrus-sasl配置
[root@10-27-0-224 ~]# vim /etc/sysconfig/saslauthd SOCKETDIR=/run/saslauthd MECH=shadow # 修改saslauthd文件把MECH的值修改为shadow FLAGS=
(4)修改smtpd.conf文件,新增以下内容
[root@10-27-0-224 ~]# vim /etc/sasl2/smtpd.conf log_level: 3 saslauthd_path:/var/run/saslauthd/mux
(5)测试cyrus-sasl功能
创建系统用户stargao,并设置密码
[root@10-27-0-224 ~]# useradd stargao &&echo 'stargao-mail' | passwd --stdin stargao Changing password for user stargao. passwd: all authentication tokens updated successfully. [root@10-27-0-224 ~]# ll /home/ total 0 drwx------ 2 stargao stargao 62 Sep 24 00:43 stargao [root@10-27-0-224 ~]# ll /var/spool/mail/ total 0 -rw-rw---- 1 stargao mail 0 Sep 24 00:43 stargao [root@10-27-0-224 ~]# userdel -r stargao # 彻底删除用户
测试stargao用户
[root@10-27-0-224 ~]# su - stargao [stargao@10-27-0-224 ~]$ mkdir -p ~/mail/.imap/INBOX [stargao@10-27-0-224 ~]$ ls -al ~/mail/.imap/ total 0 drwxrwxr-x 3 stargao stargao 19 Sep 24 00:46 . drwxrwxr-x 3 stargao stargao 19 Sep 24 00:46 .. drwxrwxr-x 2 stargao stargao 6 Sep 24 00:46 INBOX
启动cyrus-sasl服务
[root@10-27-0-224 ~]# systemctl restart saslauthd.service [root@10-27-0-224 ~]# systemctl enable saslauthd.service Created symlink from /etc/systemd/system/multi-user.target.wants/saslauthd.service to /usr/lib/systemd/system/saslauthd.service.
测试cyrus-sasl服务
[root@10-27-0-224 ~]# testsaslauthd -u stargao -p 'stargao-mail' 0: OK "Success."
postfix是一个电子邮件服务器,它为了改良sendmail邮件服务器而产生的,并且它的配置文件比sendmail简单得多,配置相当容易。
◆ 配置好域名解析:
A记录: mail.starcto.com $IP
MX记录:starcto.com mail.starcto.com
◆ 配置好域名反向解析
mail.starcto.com $IP
(1)安装postfix
[root@10-27-0-224 ~]# yum -y install postfix
第三方YUM源: https://repos.fedorapeople.org/repos/mstevens/postfix/epel-postfix.repo
(2)查看postfix安装版本
[root@10-27-0-224 ~]# postconf -d | grep mail_version mail_version = 2.10.1 milter_macro_v = $mail_name $mail_version
(3)修改postfix配置
postfix的配置选项特别多,下面我们先了解最基本的发送邮件配置
# 备份配置文件 [root@10-27-0-224 ~]# cd /etc/postfix/ [root@10-27-0-224 postfix]# mv main.cf main.cf.bak [root@10-27-0-224 postfix]# cat main.cf.bak | grep -v '#' | grep -v '^$' > main.cf
[root@10-27-0-224 ~]# vim /etc/postfix/main.cf queue_directory = /var/spool/postfix command_directory = /usr/sbin daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix mail_owner = postfix inet_interfaces = all inet_protocols = all myhostname = mail.starcto.com mydomain = starcto.com myorigin = $mydomain mydestination = $myhostname, localhost.$mydomain, localhost mynetworks = 0.0.0.0/0 # 注意增加这条,否则发生邮件时会报错Relay access denied local_recipient_maps = unknown_local_recipient_reject_code = 550 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 ffffd $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.10.1/samples readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
(4)测试postfix服务
# 启动postfix服务 [root@10-27-0-224 ~]# systemctl restart postfix.service [root@10-27-0-224 ~]# systemctl enable postfix.service # 查看postfix服务 [root@10-27-0-224 ~]# netstat -tunlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 56256/master [root@10-27-0-224 ~]# ps -ef |grep postfix root 56256 1 0 02:17 ? 00:00:00 /usr/libexec/postfix/master -w postfix 56257 56256 0 02:17 ? 00:00:00 pickup -l -t unix -u postfix 56258 56256 0 02:17 ? 00:00:00 qmgr -l -t unix -u root 56497 51150 0 02:18 pts/0 00:00:00 grep --color=auto postfix
通过上述,我们可以很明显的看到postfix已经正常启动,并且监听的是tcp的25端口。postfix启动后,我们也可以通过postfix的日志进行查看。postfix的日志文件为/var/log/maillog。
[root@10-27-0-224 ~]# tail -f /var/log/maillog Sep 22 03:47:05 10-27-0-224 postfix/sendmail[96532]: fatal: parameter inet_interfaces: no local interface found for ::1 Sep 23 03:16:03 10-27-0-224 postfix/sendmail[71098]: fatal: parameter inet_interfaces: no local interface found for ::1 Sep 24 00:56:31 10-27-0-224 postfix[39947]: fatal: parameter inet_interfaces: no local interface found for ::1 Sep 24 00:56:49 10-27-0-224 postfix[40117]: name_mask: all Sep 24 00:56:49 10-27-0-224 postfix[40117]: name_mask: subnet Sep 24 00:56:49 10-27-0-224 postfix[40117]: inet_addr_local: configured 4 IPv4 addresses Sep 24 00:56:49 10-27-0-224 postfix[40117]: inet_addr_local: configured 0 IPv6 addresses Sep 24 00:56:49 10-27-0-224 postfix[40117]: fatal: parameter inet_interfaces: no local interface found for ::1 Sep 24 02:17:06 10-27-0-224 postfix/postfix-script[56254]: starting the Postfix mail system Sep 24 02:17:06 10-27-0-224 postfix/master[56256]: daemon started -- version 2.10.1, configuration /etc/postfix
(5)测试发送邮件
[root@10-27-0-224 ~]# telnet mail.starcto.com 25 Trying 107.155.48.73... Connected to mail.starcto.com. Escape character is '^]'. 220 mail.starcto.com ESMTP Postfix mail from:admin@starcto.com 250 2.1.0 Ok rcpt to:starcto@163.com 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> This is stargao. . 250 2.0.0 Ok: queued as 8610620424C0 quit 221 2.0.0 Bye Connection closed by foreign host.
登录163邮箱,查看邮件接收情况
◆ dovecot是一个开源的IMAP和POP3邮件服务器,支持Linux/Unix系统。
◆ POP/IMAP是MUA从邮件服务器中读取邮件时使用的协议。其中,与POP3是从邮件服务器中下载邮件存起来,IMAP则是将邮件留在服务器端直接对邮件进行管理、操作。
◆ dovecot可以被其他具有相同功能的软件替代,比如:cyrus-imapd。
配置smtp与pop域名解析:
smtp.starcto.com $IP
pop.starcto.com $IP
(1)安装dovecot
[root@10-27-0-224 ~]# yum -y install dovecot dovecot-devel dovecot-mysql pam-devel
第三方yum源:http://repos.fedorapeople.org/repos/mstevens/dovecot/epel-dovecot.repo
(2)查看dovecot版本
[root@10-27-0-224 ~]# dovecot --version 2.2.36 (1f10bfa63)
(3)修改dovecot.conf配置
[root@10-27-0-224 ~]# cd /etc/dovecot/ [root@10-27-0-224 dovecot]# mv dovecot.conf dovecot.conf.bak [root@10-27-0-224 dovecot]# cat dovecot.conf.bak | grep -v '#' | grep -v '^$' > dovecot.conf [root@10-27-0-224 dovecot]# vim dovecot.conf protocols = imap pop3 listen = *
(4)修改10-auth.conf配置
[root@10-27-0-224 ~]# vim /etc/dovecot/conf.d/10-auth.conf disable_plaintext_auth = no auth_mechanisms = plain login !include auth-system.conf.ext
(5)修改10-ssl.conf,禁用ssl认证
[root@10-27-0-224 ~]# vim /etc/dovecot/conf.d/10-ssl.conf ssl = no
(6)启用dovecot日志
[root@10-27-0-224 ~]# vim /etc/dovecot/conf.d/10-logging.conf info_log_path = /var/log/dovecot_info.log debug_log_path = /var/log/dovecot_debug.log
(7)启动dovecot服务
[root@10-27-0-224 ~]# systemctl restart dovecot.service [root@10-27-0-224 ~]# systemctl enable dovecot.service Created symlink from /etc/systemd/system/multi-user.target.wants/dovecot.service to /usr/lib/systemd/system/dovecot.service.
(8)测试dovecot,出现+Ok Dovecot ready,则表示dovecot配置正确。
[root@10-27-0-224 ~]# telnet mail.starcto.com 110 Trying 107.155.48.73... Connected to mail.starcto.com. Escape character is '^]'. +OK Dovecot ready. Connection closed by foreign host. [root@10-27-0-224 ~]# telnet mail.starcto.com 143 Trying 107.155.48.73... Connected to mail.starcto.com. Escape character is '^]'. * OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
(9)foxmail客户端连接测试
注意:用户就是我们2.1部分创建的stargao用户,具体过程如下:
由上图可以看出,邮件成功登录到了服务器。
postfixadmin是一个基于web的postfix邮件发送服务器的管理工具,可以直接管理postfix的虚拟域名和邮件用户,前提是这些数据是存储在mysql或者是PostgreSQL数据库中。安装包下载地址:https://github.com/postfixadmin/postfixadmin/tags
一键部署LNMP参考:
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/128170.html
摘要:使用阿里云制作收发邮件服务器详细过程如下什么是免费开源邮件服务解决方案以最佳的方式搭建基于和开源软件的邮件服务器。 使用阿里云ECS制作IRedMail收发邮件服务器详细过程如下 1、什么是IRedMail? iRedMail - 免费、开源邮件服务解决方案以最佳的方式搭建基于 Linux/BSD 和开源软件的邮件服务器。始于 2007 年。支持 Red Hat Enterprise ...
摘要:在文件中增加以下信息以支持认证和服务。另外中的以下两个参数分别代表了你的服务器信息,是你当前主机名,其中的则是邮件服务器名。修改文件,修改其中的变量,在其中增加完成以上工作后启动三个服务。然后新增用户至此,邮件服务器的配置成功。 第一步 #apt-get update #apt-get upgrade #apt-get install postfix libsasl2-2 sasl2-...
摘要:主机端口非常昂贵,因此稍后我们会使用一个负载均衡器。注册完成后,将的配置添加到负载均衡器上。部署负载均衡器在栈中,单击添加服务旁边的下拉菜单,然后选择添加负载均衡器。如果你收到状态或的错误报告,那么需要检查负载均衡器配置,确认设置无误。 介绍 GitLab核心是集成管理Git存储库的工具。比如你希望创建一个提供服务的平台,那么GitLab将提供强大的身份验证和授权机制、工作组、问题跟踪...
摘要:一准备工作为邮件服务器添加解析虽然不加解析也能把邮件发出去,但会被大多数邮件服务器当作垃圾邮件。二配置是默认安装的邮件服务器软件。以下配置示例假设要配置的域名是,邮件服务器主机名是。 一、准备工作 为邮件服务器添加DNS解析 虽然不加DNS解析也能把邮件发出去,但会被大多数邮件服务器当作垃圾邮件。根据我们的实际经验,需要添加三条DNS解析记录:A记录、MX记录、TXT记录。比如域...
摘要:一准备工作为邮件服务器添加解析虽然不加解析也能把邮件发出去,但会被大多数邮件服务器当作垃圾邮件。二配置是默认安装的邮件服务器软件。以下配置示例假设要配置的域名是,邮件服务器主机名是。 一、准备工作 为邮件服务器添加DNS解析 虽然不加DNS解析也能把邮件发出去,但会被大多数邮件服务器当作垃圾邮件。根据我们的实际经验,需要添加三条DNS解析记录:A记录、MX记录、TXT记录。比如域...
阅读 876·2023-02-24 11:21
阅读 938·2023-02-24 10:55
阅读 1754·2023-02-24 10:47
阅读 2628·2023-02-24 10:44
阅读 475·2023-02-24 10:38
阅读 412·2022-12-25 19:44
阅读 534·2022-12-25 19:39
阅读 579·2022-12-25 19:36