赞
踩
postfix 邮件服务的安装及详解 - smile-you-me - 博客园 (cnblogs.com)
MUA(Mail User Agent)接收邮件所使用的邮件客户端,使用IMAP或POP3协议与服务器通信,如 Foxmail、Outlook、Thunderbird;
MTA(Mail Transfer Agent) 通过SMTP协议发送、转发邮件,如 postfix、sendmail;
MDA(Mail Deliver Agent)将MTA接收到的邮件保存到磁盘或指定地方,通常会进行垃圾邮件及病毒扫描,如 procmail、dropmail;
MRA(Mail Receive Agent)负责实现IMAP与POP3协议,与MUA进行交互;
SMTP(Simple Mail Transfer Protocol)传输发送邮件所使用的标准协议;
IMAP(Internet Message Access Protocol)接收邮件使用的标准协议之一;
POP3(Post Office Protocol 3) 接收邮件使用的标准协议之一。
本教程不通过外网向其他服务器发送邮件。邮箱系统整体框架为:
环境 | 工具 |
---|---|
宿主机操作系统 | win10 |
虚拟机操作系统 | centos 8 |
MTA(Mail Transfer Agent) | postfix |
MRA(Mail Receive Agent) | dovecot |
MUA(Mail User Agent) | Foxmail、Outlook |
为了方便 Foxmail 客户端解析域名,因此在 C:\Windows\System32\drivers\etc\hosts 文件中添加如下语句:
# 192.168.6.128 是虚拟机ip地址
# mail.liuqiang.com 为邮件服务器域名
192.168.6.128 mail.liuqiang.com
如何在CentOS8上安装和配置Postfix邮件服务器的方法示例 - 云+社区 - 腾讯云 (tencent.com)
Linux中如何配置Postfix邮件发送 - 开发技术 - 亿速云 (yisu.com)
postfix是Wietse Venema在IBM的GPL协议之下开发的MTA(邮件传输代理)软件。下面一段话摘自postfix的官方站点(http://www.postfix.org):“postfix是Wietse Venema想要为使用最广泛的sendmail提供替代品的一个尝试。在Internet世界中,大部分的电子邮件都是通过sendmail来投递的,大约有100万用户使用sendmail,每天投递上亿封邮件。这真实一个让人吃惊的数字。Postfix试图更快、更容易管理、更安全,同时还与sendmail保持足够的兼容性”。
# dnf list installed |grep postfix
因为 postfix 使用端口 25,放置和其他进程冲突。
# netstat -lntp | grep 25
确保软件包是最新的。
# dnf update
[root@main ~]# dnf update
上次元数据过期检查:1:40:43 前,执行于 2022年05月05日 星期四 20时23分55秒。
依赖关系解决。
无需任何处理。
完毕!
[root@main ~]#
使用 hostnamectl 命令在系统上设置主机名:
# hostnamectl set-hostname 主机名
# exec bash
[root@12345 ~]# hostnamectl set-hostname mail.liuqiang.com
[root@12345 ~]# exec bash
[root@mail ~]#
在 /etc/hosts 中添加系统的主机名和 IP:
# vim /etc/hosts
192.168.6.128 mail.liuqiang.com
特别说明:此设置主要是配置 DNS。
# dnf install postfix
[root@mail ~]# dnf install postfix 上次元数据过期检查:1:47:43 前,执行于 2022年05月05日 星期四 20时23分55秒。 依赖关系解决。 ============================================================================================================================ 软件包 架构 版本 仓库 大小 ============================================================================================================================ 安装: postfix x86_64 2:3.5.8-4.el8 baseos 1.5 M 事务概要 ============================================================================================================================ 安装 1 软件包 总下载:1.5 M 安装大小:4.3 M 确定吗?[y/N]: y 下载软件包: postfix-3.5.8-4.el8.x86_64.rpm 1.2 MB/s | 1.5 MB 00:01 ---------------------------------------------------------------------------------------------------------------------------- 总计 806 kB/s | 1.5 MB 00:01 运行事务检查 事务检查成功。 运行事务测试 事务测试成功。 运行事务 准备中 : 1/1 运行脚本: postfix-2:3.5.8-4.el8.x86_64 1/1 安装 : postfix-2:3.5.8-4.el8.x86_64 1/1 运行脚本: postfix-2:3.5.8-4.el8.x86_64 1/1 验证 : postfix-2:3.5.8-4.el8.x86_64 1/1 已安装: postfix-2:3.5.8-4.el8.x86_64 完毕! [root@mail ~]#
rpm -ql postfix
[root@mail ~]# rpm -ql postfix /etc/pam.d/smtp /etc/pam.d/smtp.postfix /etc/postfix /etc/postfix/access /etc/postfix/canonical /etc/postfix/dynamicmaps.cf /etc/postfix/dynamicmaps.cf.d /etc/postfix/generic /etc/postfix/header_checks /etc/postfix/main.cf /etc/postfix/main.cf.proto /etc/postfix/master.cf /etc/postfix/master.cf.proto /etc/postfix/postfix-files /etc/postfix/postfix-files.d /etc/postfix/relocated /etc/postfix/transport /etc/postfix/virtual /etc/sasl2/smtpd.conf /usr/bin/mailq /usr/bin/mailq.postfix /usr/bin/newaliases /usr/bin/newaliases.postfix /usr/bin/rmail /usr/bin/rmail.postfix /usr/lib/.build-id /usr/lib/.build-id/06 /usr/lib/.build-id/06/ad90d5d8642d3cd183be59c4bbd65a681afd56 /usr/lib/.build-id/08 /usr/lib/.build-id/08/0aa67dac6b94afe40120f8a64bc8c4e855d5a0 /usr/lib/.build-id/0d /usr/lib/.build-id/0d/60e0790c3499fe247c76253d08b6b6b4a23e88 /usr/lib/.build-id/0d/bcc7ec7cf17dffb7b04ef1188b0575552b63c6 /usr/lib/.build-id/12 /usr/lib/.build-id/12/9268411b51a31b60f306ccb5cb5d362fdf2b19 /usr/lib/.build-id/17 /usr/lib/.build-id/17/4f0a4a6f7c91b3f87dfe2d619c5fc111b8be34 /usr/lib/.build-id/1c /usr/lib/.build-id/1c/0d1f0aa6d791b5bef1c5177508ce0771ab688d /usr/lib/.build-id/20 /usr/lib/.build-id/20/2141c6789e08b05bdc443ddcae033091fb09da /usr/lib/.build-id/36 /usr/lib/.build-id/36/57204f9fa0d44ef81a35949c44c0b4a38eb8b8 /usr/lib/.build-id/38 /usr/lib/.build-id/38/75df217a653d18feb660e36d7414daeb0bfafa /usr/lib/.build-id/38/7fc863c90aa04c020156d88647639d7770d547 /usr/lib/.build-id/3e /usr/lib/.build-id/3e/920ba949a5804b296d81903cc3b62b359d359e /usr/lib/.build-id/40 /usr/lib/.build-id/40/cc8b7a3afd804a5ea2c7a15ee02a9a0ee9eb9c /usr/lib/.build-id/44 /usr/lib/.build-id/44/27296aa6eef6687d291e84234a096b6d0058ab /usr/lib/.build-id/4a /usr/lib/.build-id/4a/d76f9adf3e25624fff8f30f59fe576e9f1d6bf /usr/lib/.build-id/4f /usr/lib/.build-id/4f/65b32edab62f99178e708f7ea263964067d8bd /usr/lib/.build-id/50 /usr/lib/.build-id/50/46c754afb27c022365f7d5701dc8e36d9c9d6c /usr/lib/.build-id/52 /usr/lib/.build-id/52/91b6f2d9a3beae0a5c74533fdfd2ea89d43284 /usr/lib/.build-id/59 /usr/lib/.build-id/59/02710e620ce87e1ea9503fce56439ed002a202 /usr/lib/.build-id/67 /usr/lib/.build-id/67/44df4f9b67fbc4faec4495b202587a5d826a92 /usr/lib/.build-id/69 /usr/lib/.build-id/69/e63b3713d304102108877047d5a13eda10d193 /usr/lib/.build-id/6a /usr/lib/.build-id/6a/ca25d17fb28e73ae98b61676c719aab1798d7b /usr/lib/.build-id/6d /usr/lib/.build-id/6d/78cf6e864b2f686c811c337fd73515be80d479 /usr/lib/.build-id/7b /usr/lib/.build-id/7b/53b7823d33d1b939a5a572fe1393ff8e8f65ec /usr/lib/.build-id/84 /usr/lib/.build-id/84/3fdbd50337489045a6639ab875ecbc1dbc5e58 /usr/lib/.build-id/88 /usr/lib/.build-id/88/292a452ee9a8945ce5d4060c9871e0059aca95 /usr/lib/.build-id/88/642cb933fb17a824860e8b04f79504de6964cd /usr/lib/.build-id/9b /usr/lib/.build-id/9b/9a4d8f014811c676cd57e45dc3bfb65748d351 /usr/lib/.build-id/a2 /usr/lib/.build-id/a2/1ec7c59f06569279809328e12108ff620ce356 /usr/lib/.build-id/a5 /usr/lib/.build-id/a5/1f793502d85a5a0ae7fafeb08cf88dad3d2aeb /usr/lib/.build-id/a5/44e1b6787fcfc7ae1c435fbd3a864c1e66b12b /usr/lib/.build-id/b5 /usr/lib/.build-id/b5/b88511f66429c6b3568455e0b75b1f10d9d866 /usr/lib/.build-id/b6 /usr/lib/.build-id/b6/73ea91fca421accb0605e251cdb54cec9137d1 /usr/lib/.build-id/b9 /usr/lib/.build-id/b9/20916cf8292d3ba0aef6932723f3c6c4094ec6 /usr/lib/.build-id/bd /usr/lib/.build-id/bd/728842e0018212aa2f9d2691597dfd0ba78aff /usr/lib/.build-id/cd /usr/lib/.build-id/cd/cd7bfa21db91b347bc4cf0b7fa52a411dcd186 /usr/lib/.build-id/ce /usr/lib/.build-id/ce/37060c99e25eaebd59264f2119a52ab8ccb795 /usr/lib/.build-id/d1 /usr/lib/.build-id/d1/418e86561e0d5fae575268306ad3cc068ca129 /usr/lib/.build-id/d3 /usr/lib/.build-id/d3/3b5e3bb36128d962227b0fdea90996938d6fd4 /usr/lib/.build-id/d3/faabef708209dcda940d02831c76049dceebb1 /usr/lib/.build-id/db /usr/lib/.build-id/db/49d25b92c6d26cb83f9a079b3702a6d769526f /usr/lib/.build-id/df /usr/lib/.build-id/df/093643cab807b19547d1b3906b127c2bca5dcf /usr/lib/.build-id/e6 /usr/lib/.build-id/e6/1d5fbcc64fe285face5b4e960ad62ea58db396 /usr/lib/.build-id/ec /usr/lib/.build-id/ec/235e9fa7d6af2d1af88a01bd4892dc860a09cc /usr/lib/.build-id/ef /usr/lib/.build-id/ef/889cb14a641174f1feeb2e65318a1b4750744f /usr/lib/.build-id/ef/889cb14a641174f1feeb2e65318a1b4750744f.1 /usr/lib/.build-id/f0 /usr/lib/.build-id/f0/a7ffdaaf6b91dfd4fc6955e969cdaa58c9a2fa /usr/lib/.build-id/f0/a7ffdaaf6b91dfd4fc6955e969cdaa58c9a2fa.1 /usr/lib/.build-id/f5 /usr/lib/.build-id/f5/759db1d90f9dc6631c9cd9e813707ca43d3e8b /usr/lib/.build-id/f7 /usr/lib/.build-id/f7/b2b101d9548ad5a1fc9889d33f3f3369e79aca /usr/lib/sendmail /usr/lib/sendmail.postfix /usr/lib/systemd/system/postfix.service /usr/lib64/postfix /usr/lib64/postfix/libpostfix-dns.so /usr/lib64/postfix/libpostfix-global.so /usr/lib64/postfix/libpostfix-master.so /usr/lib64/postfix/libpostfix-tls.so /usr/lib64/postfix/libpostfix-util.so /usr/libexec/postfix /usr/libexec/postfix/aliasesdb /usr/libexec/postfix/anvil /usr/libexec/postfix/bounce /usr/libexec/postfix/chroot-update /usr/libexec/postfix/cleanup /usr/libexec/postfix/discard /usr/libexec/postfix/dnsblog /usr/libexec/postfix/error /usr/libexec/postfix/flush /usr/libexec/postfix/lmtp /usr/libexec/postfix/local /usr/libexec/postfix/master /usr/libexec/postfix/nqmgr /usr/libexec/postfix/oqmgr /usr/libexec/postfix/pickup /usr/libexec/postfix/pipe /usr/libexec/postfix/post-install /usr/libexec/postfix/postfix-script /usr/libexec/postfix/postfix-tls-script /usr/libexec/postfix/postfix-wrapper /usr/libexec/postfix/postlogd /usr/libexec/postfix/postmulti-script /usr/libexec/postfix/postscreen /usr/libexec/postfix/proxymap /usr/libexec/postfix/qmgr /usr/libexec/postfix/qmqpd /usr/libexec/postfix/scache /usr/libexec/postfix/showq /usr/libexec/postfix/smtp /usr/libexec/postfix/smtpd /usr/libexec/postfix/spawn /usr/libexec/postfix/tlsmgr /usr/libexec/postfix/tlsproxy /usr/libexec/postfix/trivial-rewrite /usr/libexec/postfix/verify /usr/libexec/postfix/virtual /usr/sbin/postalias /usr/sbin/postcat /usr/sbin/postconf /usr/sbin/postdrop /usr/sbin/postfix /usr/sbin/postkick /usr/sbin/postlock /usr/sbin/postlog /usr/sbin/postmap /usr/sbin/postmulti /usr/sbin/postqueue /usr/sbin/postsuper /usr/sbin/posttls-finger /usr/sbin/sendmail /usr/sbin/sendmail.postfix /usr/sbin/smtp-sink /usr/sbin/smtp-source /usr/share/doc/postfix /usr/share/doc/postfix/COMPATIBILITY /usr/share/doc/postfix/LICENSE /usr/share/doc/postfix/README-Postfix-SASL-RedHat.txt /usr/share/doc/postfix/README-RedHat.txt /usr/share/doc/postfix/README_FILES /usr/share/doc/postfix/README_FILES/AAAREADME /usr/share/doc/postfix/README_FILES/ADDRESS_CLASS_README /usr/share/doc/postfix/README_FILES/ADDRESS_REWRITING_README /usr/share/doc/postfix/README_FILES/ADDRESS_VERIFICATION_README /usr/share/doc/postfix/README_FILES/BACKSCATTER_README /usr/share/doc/postfix/README_FILES/BASIC_CONFIGURATION_README /usr/share/doc/postfix/README_FILES/BUILTIN_FILTER_README /usr/share/doc/postfix/README_FILES/COMPATIBILITY_README /usr/share/doc/postfix/README_FILES/CONNECTION_CACHE_README /usr/share/doc/postfix/README_FILES/CONTENT_INSPECTION_README /usr/share/doc/postfix/README_FILES/DATABASE_README /usr/share/doc/postfix/README_FILES/DB_README /usr/share/doc/postfix/README_FILES/DEBUG_README /usr/share/doc/postfix/README_FILES/DSN_README /usr/share/doc/postfix/README_FILES/ETRN_README /usr/share/doc/postfix/README_FILES/FILTER_README /usr/share/doc/postfix/README_FILES/FORWARD_SECRECY_README /usr/share/doc/postfix/README_FILES/INSTALL /usr/share/doc/postfix/README_FILES/IPV6_README /usr/share/doc/postfix/README_FILES/LINUX_README /usr/share/doc/postfix/README_FILES/LOCAL_RECIPIENT_README /usr/share/doc/postfix/README_FILES/MAILDROP_README /usr/share/doc/postfix/README_FILES/MEMCACHE_README /usr/share/doc/postfix/README_FILES/MILTER_README /usr/share/doc/postfix/README_FILES/MULTI_INSTANCE_README /usr/share/doc/postfix/README_FILES/NFS_README /usr/share/doc/postfix/README_FILES/OVERVIEW /usr/share/doc/postfix/README_FILES/PACKAGE_README /usr/share/doc/postfix/README_FILES/POSTSCREEN_README /usr/share/doc/postfix/README_FILES/QSHAPE_README /usr/share/doc/postfix/README_FILES/RELEASE_NOTES /usr/share/doc/postfix/README_FILES/RESTRICTION_CLASS_README /usr/share/doc/postfix/README_FILES/SASL_README /usr/share/doc/postfix/README_FILES/SCHEDULER_README /usr/share/doc/postfix/README_FILES/SMTPD_ACCESS_README /usr/share/doc/postfix/README_FILES/SMTPD_POLICY_README /usr/share/doc/postfix/README_FILES/SMTPD_PROXY_README /usr/share/doc/postfix/README_FILES/SOHO_README /usr/share/doc/postfix/README_FILES/STANDARD_CONFIGURATION_README /usr/share/doc/postfix/README_FILES/STRESS_README /usr/share/doc/postfix/README_FILES/TLS_LEGACY_README /usr/share/doc/postfix/README_FILES/TLS_README /usr/share/doc/postfix/README_FILES/TUNING_README /usr/share/doc/postfix/README_FILES/ULTRIX_README /usr/share/doc/postfix/README_FILES/UUCP_README /usr/share/doc/postfix/README_FILES/VERP_README /usr/share/doc/postfix/README_FILES/VIRTUAL_README /usr/share/doc/postfix/README_FILES/XCLIENT_README /usr/share/doc/postfix/README_FILES/XFORWARD_README /usr/share/doc/postfix/TLS_ACKNOWLEDGEMENTS /usr/share/doc/postfix/TLS_LICENSE /usr/share/doc/postfix/bounce.cf.default /usr/share/doc/postfix/examples /usr/share/doc/postfix/examples/chroot-setup /usr/share/doc/postfix/examples/chroot-setup/LINUX2 /usr/share/doc/postfix/examples/qmail-local /usr/share/doc/postfix/examples/qmail-local/qmail-local.txt /usr/share/doc/postfix/examples/smtpd-policy /usr/share/doc/postfix/examples/smtpd-policy/README.SPF /usr/share/doc/postfix/examples/smtpd-policy/greylist.pl /usr/share/doc/postfix/main.cf.default /usr/share/man/man1/mailq.1.gz /usr/share/man/man1/mailq.postfix.1.gz /usr/share/man/man1/newaliases.1.gz /usr/share/man/man1/newaliases.postfix.1.gz /usr/share/man/man1/postalias.1.gz /usr/share/man/man1/postcat.1.gz /usr/share/man/man1/postconf.1.gz /usr/share/man/man1/postdrop.1.gz /usr/share/man/man1/postfix-tls.1.gz /usr/share/man/man1/postfix.1.gz /usr/share/man/man1/postkick.1.gz /usr/share/man/man1/postlock.1.gz /usr/share/man/man1/postlog.1.gz /usr/share/man/man1/postmap.1.gz /usr/share/man/man1/postmulti.1.gz /usr/share/man/man1/postqueue.1.gz /usr/share/man/man1/postsuper.1.gz /usr/share/man/man1/posttls-finger.1.gz /usr/share/man/man1/sendmail.postfix.1.gz /usr/share/man/man1/smtp-sink.1.gz /usr/share/man/man1/smtp-source.1.gz /usr/share/man/man5/access.5.gz /usr/share/man/man5/aliases.5.gz /usr/share/man/man5/aliases.postfix.5.gz /usr/share/man/man5/body_checks.5.gz /usr/share/man/man5/bounce.5.gz /usr/share/man/man5/canonical.5.gz /usr/share/man/man5/cidr_table.5.gz /usr/share/man/man5/generic.5.gz /usr/share/man/man5/header_checks.5.gz /usr/share/man/man5/master.5.gz /usr/share/man/man5/memcache_table.5.gz /usr/share/man/man5/nisplus_table.5.gz /usr/share/man/man5/postconf.5.gz /usr/share/man/man5/postfix-wrapper.5.gz /usr/share/man/man5/regexp_table.5.gz /usr/share/man/man5/relocated.5.gz /usr/share/man/man5/socketmap_table.5.gz /usr/share/man/man5/tcp_table.5.gz /usr/share/man/man5/transport.5.gz /usr/share/man/man5/virtual.5.gz /usr/share/man/man8/anvil.8.gz /usr/share/man/man8/bounce.8.gz /usr/share/man/man8/cleanup.8.gz /usr/share/man/man8/defer.8.gz /usr/share/man/man8/discard.8.gz /usr/share/man/man8/dnsblog.8.gz /usr/share/man/man8/error.8.gz /usr/share/man/man8/flush.8.gz /usr/share/man/man8/lmtp.8.gz /usr/share/man/man8/local.8.gz /usr/share/man/man8/master.8.gz /usr/share/man/man8/oqmgr.8.gz /usr/share/man/man8/pickup.8.gz /usr/share/man/man8/pipe.8.gz /usr/share/man/man8/postlogd.8.gz /usr/share/man/man8/postscreen.8.gz /usr/share/man/man8/proxymap.8.gz /usr/share/man/man8/qmgr.8.gz /usr/share/man/man8/qmqpd.8.gz /usr/share/man/man8/scache.8.gz /usr/share/man/man8/sendmail.8.gz /usr/share/man/man8/showq.8.gz /usr/share/man/man8/smtp.8.gz /usr/share/man/man8/smtpd.8.gz /usr/share/man/man8/smtpd.postfix.8.gz /usr/share/man/man8/spawn.8.gz /usr/share/man/man8/tlsmgr.8.gz /usr/share/man/man8/tlsproxy.8.gz /usr/share/man/man8/trace.8.gz /usr/share/man/man8/trivial-rewrite.8.gz /usr/share/man/man8/verify.8.gz /usr/share/man/man8/virtual.8.gz /var/lib/misc/postfix.aliasesdb-stamp /var/lib/postfix /var/spool/postfix /var/spool/postfix/active /var/spool/postfix/bounce /var/spool/postfix/corrupt /var/spool/postfix/defer /var/spool/postfix/deferred /var/spool/postfix/flush /var/spool/postfix/hold /var/spool/postfix/incoming /var/spool/postfix/maildrop /var/spool/postfix/pid /var/spool/postfix/private /var/spool/postfix/public /var/spool/postfix/saved /var/spool/postfix/trace [root@mail ~]#
成功安装 Postfix 后,运行以下命令启动并启用 Postfix 服务:
# systemctl start postfix
# systemctl enable postfix
[root@mail ~]# systemctl start postfix
[root@mail ~]# systemctl enable postfix
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@mail ~]#
检查 Postfix 状态,请运行以下 systemctl 命令:
# systemctl status postfix
[root@mail ~]# systemctl status postfix ● postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2022-05-05 22:17:40 EDT; 2min 0s ago Main PID: 4811 (master) Tasks: 3 (limit: 23330) Memory: 4.4M CGroup: /system.slice/postfix.service ├─4811 /usr/libexec/postfix/master -w ├─4812 pickup -l -t unix -u └─4813 qmgr -l -t unix -u 5月 05 22:17:38 mail.liuqiang.com systemd[1]: Starting Postfix Mail Transport Agent... 5月 05 22:17:39 mail.liuqiang.com restorecon[4732]: /usr/sbin/restorecon: lstat(/var/spool/postfix/pid/master.pid) failed: > 5月 05 22:17:40 mail.liuqiang.com postfix/master[4811]: daemon started -- version 3.5.8, configuration /etc/postfix 5月 05 22:17:40 mail.liuqiang.com systemd[1]: Started Postfix Mail Transport Agent. [root@mail ~]#
mail.cf:postfix主要的配置文件。master.cf:postfix的master进程的配置文件。
myhostname 参数指定运行postfix邮件系统的主机的主机名。缺省情况该值被设定为本地机器名。也可以指定该值,需要注意的是,要指定完整的主机名,如下:
myhostname = mail.domain.com
mydomain参数指定你的域名,缺省情况 postfix 将 myhostname 的第一部分删除而作为 mydomain 的值。也可以指定该值,例如:
mydomain = domain.com
myorigin 参数指明发件人所在的域名。如果你的用户的邮件地址为 user@domain.com 则该参数指定@后面的域名。
缺省情况 postfix 使用本地主机名作为 myorigin。
比如:安装 postfix 的主机为 mail.domain.com 则我们可以这样指定 myorigin:
myorigin = domain.com
可以引用其他参数,如:
myorigin = $mydomain
mydestination 参数指定 postfix 接收邮件时收件人的域名,换句话说,也就是你的 postfix 系统要接收什么样的邮件。
如果你的用户的邮件地址为 user@domain.com, 也就是你的域为 domain.com, 则你就需要接收所有收件人为 user_name@domain.com 的邮件。
缺省情况 postfix使用本地主机名作为mydestination。示例:
mydestination = $mydomain
mydestination = domain.com
mynetworks 参数指定你所在的网络的网络地址,postfix 系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问。你可以用标准的A、B、C类网络地址,也可以用CIDR(无类域间路由)地址来表示,如:
192.168.1.0/24
192.168.1.0/26
inet_interfaces 参数指定 postfix 系统监听的网络接口。缺省情况 postfix 监听所有的网络接口。如果你的 postfix 运行在一个虚拟的 ip 地址上,则必须指定其监听的地址。如:
inet_interfaces = all
inet_interface = 192.168.1.1
设置邮箱相对于用户主目录的路径,还指定要使用的邮箱样式。
Mbox 主要特点就是“所有邮件都存放到一个文件里”。每个邮件之间以特定的标记分割。
Maildir 每一封邮件保存成一个文件,每个文件名称一般有一定的规律,例如会包含时间戳、pid及inode节点号等。
inet_protocols 参数指定 postfix 系统使用协议。
此系统将邮件中继到的目标域列表。如果将其设置为空白,我们确保我们的邮件服务器不会充当不受信任网络的开放中继。
myhostname = mail.liuqiang.com
mydomain = liuqiang.com
myorigin = $mydomain
## 取消注释并将 inet_interfaces 设置为 all##
inet_interfaces = all
## 更改为 all ##
inet_protocols = all
## 注释 ##
#mydestination = $myhostname, localhost.$mydomain, localhost
## 取消注释 ##
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
## 取消注释并添加 IP 范围 ##
mynetworks = 192.168.6.0/24, 127.0.0.0/8
## 取消注释 ##
home_mailbox = Maildir/
完成后,保存并退出配置文件。重新启动 postfix 服务以使更改生效:
# systemctl restart postfix
[root@mail ~]# netstat -lntp | grep 25
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6153/master
tcp6 0 0 :::25 :::* LISTEN 6153/master
[root@mail ~]#
# useradd user1
# passwd user1
# useradd user2
# passwd user2
[root@mail ~]# ls /home/ -l 总用量 4 drwx------. 18 lq lq 4096 5月 4 23:48 lq [root@mail ~]# [root@mail ~]# useradd user1 [root@mail ~]# passwd user1 更改用户 user1 的密码 。 新的 密码: 重新输入新的 密码: passwd:所有的身份验证令牌已经成功更新。 [root@mail ~]# useradd user2 [root@mail ~]# passwd user2 更改用户 user2 的密码 。 新的 密码: 重新输入新的 密码: passwd:所有的身份验证令牌已经成功更新。 [root@mail ~]# [root@mail ~]# ls /home/ -l 总用量 4 drwx------. 18 lq lq 4096 5月 4 23:48 lq drwx------. 3 user1 user1 78 5月 5 23:35 user1 drwx------. 3 user2 user2 78 5月 5 23:36 user2 [root@mail ~]#
通过 telnet 连接 postfix,让 user1 向 user2 发送一份邮件进行测试。
# 通过 telnet 连接 postfix [root@mail ~]# telnet 192.168.6.128 25 Trying 192.168.6.128... Connected to 192.168.6.128. Escape character is '^]'. 220 mail.liuqiang.com ESMTP Postfix ehlo localhost 250-mail.liuqiang.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250 SMTPUTF8 # 邮件发送者 mail from:<user1@liuqiang.com> 250 2.1.0 Ok # 邮件接收者 rcpt to:user2@liuqiang.com 250 2.1.5 Ok # 邮件内容 data 354 End data with <CR><LF>.<CR><LF> 2022.05.06 user1-192.168.6.128-send . Subject:test mail test mail content . 250 2.0.0 Ok: queued as 0452560D8241 # 退出 telnet quit 221 2.0.0 Bye Connection closed by foreign host. [root@mail ~]#
邮件接收成功后,会在 user2 家目录下创建 Maildir 目录,邮件报错在 Maildir 目录 new 目录中。
[root@mail ~]# tree /home/user2/Maildir/ /home/user2/Maildir/ ├── cur ├── new │ └── 1651808648.Vfd00I411a2efM345156.mail.liuqiang.com └── tmp 3 directories, 1 file [root@mail ~]# [root@mail ~]# [root@mail ~]# cat /home/user2/Maildir/new/1651808648.Vfd00I411a2efM345156.mail.liuqiang.com Return-Path: <user1@liuqiang.com> X-Original-To: user2@liuqiang.com Delivered-To: user2@liuqiang.com Received: from localhost (unknown [192.168.6.128]) by mail.liuqiang.com (Postfix) with ESMTP id 0452560D8241 for <user2@liuqiang.com>; Thu, 5 May 2022 23:42:49 -0400 (EDT) Message-Id: <20220506034258.0452560D8241@mail.liuqiang.com> Date: Thu, 5 May 2022 23:42:49 -0400 (EDT) From: user1@liuqiang.com 2022.05.06 user1-192.168.6.128-send . Subject:test mail test mail content [root@mail ~]# [root@mail ~]#
通过以上日志可以确定,user2 接收邮件成功。
Postfix 邮件服务器邮件日志保存在文件 /var/log/maillog 中,使用以下命令查看实时日志:
# tail -f /var/log/maillog
[root@mail ~]# tail -f /var/log/maillog
May 5 23:32:42 main postfix/master[6153]: daemon started -- version 3.5.8, configuration /etc/postfix
May 5 23:42:13 main postfix/smtpd[6316]: warning: numeric hostname: 192.168.6.128
May 5 23:42:13 main postfix/smtpd[6316]: connect from unknown[192.168.6.128]
May 5 23:42:39 main postfix/smtpd[6316]: discarding EHLO keywords: CHUNKING
May 5 23:42:58 main postfix/smtpd[6316]: 0452560D8241: client=unknown[192.168.6.128]
May 5 23:44:08 main postfix/cleanup[6328]: 0452560D8241: message-id=<20220506034258.0452560D8241@mail.liuqiang.com>
May 5 23:44:08 main postfix/qmgr[6155]: 0452560D8241: from=<user1@liuqiang.com>, size=389, nrcpt=1 (queue active)
May 5 23:44:08 main postfix/local[6338]: 0452560D8241: to=<user2@liuqiang.com>, relay=local, delay=79, delays=79/0.01/0/0, dsn=2.0.0, status=sent (delivered to maildir)
May 5 23:44:08 main postfix/qmgr[6155]: 0452560D8241: removed
May 5 23:44:14 main postfix/smtpd[6316]: disconnect from unknown[192.168.6.128] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
^C
[root@mail ~]#
邮件服务器搭建之:详解Dovecot配置 - enumx - 博客园 (cnblogs.com)
Dovecot配置笔记_Inosin_Wu的博客-CSDN博客
LINUX 配置dovecot服务_李赟杰的博客-CSDN博客_启动dovecot服务
Dovecot是一个安全性较好的POP3/IMAP服务器软件,响应速度快而且扩展性好,支持 Linux/Unix 系统。
POP / IMAP 是 MUA 从邮件服务器中读取邮件时使用的协议。其中,与 POP3 是从邮件服务器中下载邮件比起来,IMAP4 则是将邮件留在服务器端直接对邮件进行管理、操作。而 Dovecot 是一个比较新的软件,由 Timo Sirainen 开发,最初发布于 2002年7月。作者将安全性考虑在第一,所以 Dovecot 在安全性方面比较出众。另外,Dovecot 支持多种认证方式,所以在功能方面也比较符合一般的应用。
# dnf list installed |grep dovecot
因为 postfix 使用端口 25,放置和其他进程冲突。
# netstat -lntp | grep 25
确保软件包是最新的。
# dnf update
[root@mail user1]# dnf update
上次元数据过期检查:2:28:18 前,执行于 2022年05月06日 星期五 00时25分08秒。
依赖关系解决。
无需任何处理。
完毕!
[root@mail user1]#
dnf install dovecot
[root@mail ~]# dnf install dovecot 上次元数据过期检查:2:29:23 前,执行于 2022年05月06日 星期五 00时25分08秒。 依赖关系解决。 ============================================================================================================================ 软件包 架构 版本 仓库 大小 ============================================================================================================================ 安装: dovecot x86_64 1:2.3.16-2.el8 appstream 5.2 M 安装依赖关系: clucene-core x86_64 2.3.3.4-31.20130812.e8e3d20git.el8 appstream 596 k 事务概要 ============================================================================================================================ 安装 2 软件包 总下载:5.8 M 安装大小:20 M 确定吗?[y/N]: y 下载软件包: (1/2): clucene-core-2.3.3.4-31.20130812.e8e3d20git.el8.x86_64.rpm 758 kB/s | 596 kB 00:00 (2/2): dovecot-2.3.16-2.el8.x86_64.rpm 1.5 MB/s | 5.2 MB 00:03 ---------------------------------------------------------------------------------------------------------------------------- 总计 1.4 MB/s | 5.8 MB 00:04 运行事务检查 事务检查成功。 运行事务测试 事务测试成功。 运行事务 准备中 : 1/1 安装 : clucene-core-2.3.3.4-31.20130812.e8e3d20git.el8.x86_64 1/2 运行脚本: dovecot-1:2.3.16-2.el8.x86_64 2/2 安装 : dovecot-1:2.3.16-2.el8.x86_64 2/2 运行脚本: dovecot-1:2.3.16-2.el8.x86_64 2/2 验证 : clucene-core-2.3.3.4-31.20130812.e8e3d20git.el8.x86_64 1/2 验证 : dovecot-1:2.3.16-2.el8.x86_64 2/2 已安装: clucene-core-2.3.3.4-31.20130812.e8e3d20git.el8.x86_64 dovecot-1:2.3.16-2.el8.x86_64 完毕! [root@mail ~]#
[root@mail ~]# tree /etc/dovecot/ /etc/dovecot/ ├── conf.d │ ├── 10-auth.conf │ ├── 10-auth.conf.rpmsave │ ├── 10-director.conf │ ├── 10-logging.conf │ ├── 10-mail.conf │ ├── 10-mail.conf.rpmsave │ ├── 10-master.conf │ ├── 10-metrics.conf │ ├── 10-ssl.conf │ ├── 10-ssl.conf.rpmsave │ ├── 15-lda.conf │ ├── 15-mailboxes.conf │ ├── 20-imap.conf │ ├── 20-lmtp.conf │ ├── 20-pop3.conf │ ├── 20-submission.conf │ ├── 90-acl.conf │ ├── 90-plugin.conf │ ├── 90-quota.conf │ ├── auth-checkpassword.conf.ext │ ├── auth-deny.conf.ext │ ├── auth-dict.conf.ext │ ├── auth-ldap.conf.ext │ ├── auth-master.conf.ext │ ├── auth-passwdfile.conf.ext │ ├── auth-sql.conf.ext │ ├── auth-static.conf.ext │ └── auth-system.conf.ext ├── dovecot.conf └── dovecot.conf.rpmsave 1 directory, 30 files [root@mail ~]#
配置文件功能说明:
# /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp submission # 定义电子邮箱支持的协议
# /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth= no # 允许用户明文进行密码验证(暂未开启加密,所以需要添加该参数允许用户明文登录)
# /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir # 定义邮件格式和存储路径
# /etc/dovecot/conf.d/10-ssl.conf
ssl = no
完成后,保存并退出配置文件。重新启动 dovecot 服务以使更改生效:
service dovecot restart
[root@mail ~]# service dovecot restart
Redirecting to /bin/systemctl restart dovecot.service
[root@mail ~]#
netstat -lntp | grep dovecot
[root@mail ~]# netstat -lntp | grep dovecot
tcp 0 0 0.0.0.0:587 0.0.0.0:* LISTEN 10864/dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 10864/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 10864/dovecot
tcp6 0 0 :::587 :::* LISTEN 10864/dovecot
tcp6 0 0 :::110 :::* LISTEN 10864/dovecot
tcp6 0 0 :::143 :::* LISTEN 10864/dovecot
[root@mail ~]#
[root@mail ~]# tree /home/user1/Maildir/ /home/user1/Maildir/ ├── cur ├── new └── tmp 3 directories, 0 files [root@mail ~]# [root@mail ~]# tree /home/user2/Maildir/ /home/user2/Maildir/ ├── cur ├── new └── tmp 3 directories, 0 files [root@mail ~]#
通过以上信息,可以确定 user1 和 user2 中无相关邮件。
user1 使用 POP3 协议关联账户。具体操作步骤如下:
user1 使用 POP3 协议关联账户。具体操作步骤如下:
测试思路:
[root@mail ~]# tree /home/user1/Maildir/ /home/user1/Maildir/ ├── cur │ └── 1651823249.Vfd00I60d26feM405022.mail.liuqiang.com:2,S ├── dovecot.index.log ├── dovecot.list.index.log ├── dovecot-uidlist ├── dovecot-uidvalidity ├── dovecot-uidvalidity.6274cb15 ├── new └── tmp 3 directories, 6 files [root@mail ~]# [root@mail ~]# [root@mail ~]# cat /home/user1/Maildir/cur/1651823249.Vfd00I60d26feM405022.mail.liuqiang.com\:2\,S Return-Path: <user2@liuqiang.com> X-Original-To: user1@liuqiang.com Delivered-To: user1@liuqiang.com Received: from LAPTOP-7NMG10E6 (unknown [192.168.6.1]) by mail.liuqiang.com (Postfix) with ESMTPS id 603B860D8240 for <user1@liuqiang.com>; Fri, 6 May 2022 03:47:29 -0400 (EDT) From: user2 <user2@liuqiang.com> To: user1 <user1@liuqiang.com> Subject: =?utf-8?B?5Zue5aSNOiDmtYvor5XmlLblj5E=?= Date: Fri, 6 May 2022 15:47:29 +0800 References: <202205061531042523313@liuqiang.com> X-Priority: 3 X-Has-Attach: no X-GUID: 25C1FE08-8E9C-47E9-9389-781CA3624BC9 X-Mailer: Foxmail 7.2.23.121[cn] Mime-Version: 1.0 Message-ID: <202205061547291309014@liuqiang.com> Content-Type: multipart/alternative; boundary="----=_001_NextPart007814063182_=----" This is a multi-part message in MIME format. ------=_001_NextPart007814063182_=---- Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 DQp1c2VyMSDkvaDlpb3vvIENCiAgICDmnKzpgq7ku7blhoXlrrnvvJoyMDIyLjA1LjA277yBDQoN Cg0KDQp1c2VyMQ0K ------=_001_NextPart007814063182_=---- Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable <html><head></head><body><div class=3D"">user2 =E6=94=B6=E5=88=B0</div><di= v> </div><hr style=3D"WIDTH: 210px; HEIGHT: 1px" color=3D"#b5c4df" si= ze=3D"1" align=3D"left"><div><span><div style=3D"MARGIN: 10px; FONT-FAMILY= : verdana; FONT-SIZE: 10pt"><div>user2</div></div></span></div><blockquote= style=3D"margin-Top: 0px; margin-Bottom: 0px; margin-Left: 0.5em; margin-= Right: inherit"><div> </div><div style=3D"border:none;border-top:soli= d #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style=3D"PADDING-RIGHT: 8p= x; PADDING-LEFT: 8px; FONT-SIZE: 12px;FONT-FAMILY:tahoma;COLOR:#000000; BA= CKGROUND: #efefef; PADDING-BOTTOM: 8px; PADDING-TOP: 8px"><div><b>=E5=8F= =91=E4=BB=B6=E4=BA=BA=EF=BC=9A</b> <a href=3D"mailto:user1@liuqiang.c= om">user1</a></div><div><b>=E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4=EF=BC=9A</= b> 2022-05-06 15:31</div><div><b>=E6=94=B6=E4=BB=B6=E4=BA=BA=EF= =BC=9A</b> <a href=3D"mailto:user2@liuqiang.com">user2</a></div><div>= <b>=E4=B8=BB=E9=A2=98=EF=BC=9A</b> =E6=B5=8B=E8=AF=95=E6=94=B6=E5=8F= =91</div></div></div><div><div class=3D""><style>div.FoxDIV_20220506154610= 249 { font-size: 10.5pt }=0Adiv.FoxDIV_20220506154610249 { line-height: 1.= 5; }=0Adiv.FoxDIV_20220506154610249 { font-size: 14px; font-family: "Micro= soft YaHei UI"; color: rgb(0, 0, 0); line-height: 1.5; }=0A</style><div st= yle=3D"height:initial" class=3D"FoxDIV_20220506154610249">=0A<div foxmail_= class=3D"mail_content_body">=0A<div><span></span><br></div>=0A<div>user1 = =E4=BD=A0=E5=A5=BD=EF=BC=81</div><div><span microsoft=3D"" yahei=3D"" ui";= =3D"" font-size:=3D"" 14px;=3D"" color:=3D"" rgb(0,=3D"" 0,=3D"" 0);=3D"" = background-color:=3D"" rgba(0,=3D"" font-weight:=3D"" normal;=3D"" font-st= yle:=3D"" normal;text-decoration:=3D"" none;"=3D""> <span sty= le=3D"font-size: 21px;">=E6=9C=AC=E9=82=AE=E4=BB=B6=E5=86=85=E5=AE=B9=EF= =BC=9A2022.05.06=EF=BC=81</span></span></div><div><span microsoft=3D"" yah= ei=3D"" ui";=3D"" font-size:=3D"" 14px;=3D"" color:=3D"" rgb(0,=3D"" 0,=3D= "" 0);=3D"" background-color:=3D"" rgba(0,=3D"" font-weight:=3D"" normal;= =3D"" font-style:=3D"" normal;text-decoration:=3D"" none;"=3D""><span styl= e=3D"font-size: 21px;"><br></span></span></div><hr style=3D"width: 210px; = height: 1px;" color=3D"#b5c4df" size=3D"1" align=3D"left">=0A<div><span><d= iv style=3D"MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt"><div>user= 1</div></div></span></div>=0A</div></div></div></div></blockquote></body><= /html> ------=_001_NextPart007814063182_=------ [root@mail ~]# [root@mail ~]# [root@mail ~]# [root@mail ~]# [root@mail ~]# tree /home/user2/Maildir/ /home/user2/Maildir/ ├── cur │ └── 1651822264.Vfd00I411a2efM576404.mail.liuqiang.com:2,RS ├── dovecot.index.cache ├── dovecot.index.log ├── dovecot.list.index.log ├── dovecot-uidlist ├── dovecot-uidvalidity ├── dovecot-uidvalidity.6274ccbb ├── new └── tmp 3 directories, 7 files [root@mail ~]# [root@mail ~]# [root@mail ~]# cat /home/user2/Maildir/cur/1651822264.Vfd00I411a2efM576404.mail.liuqiang.com\:2\,RS Return-Path: <user1@liuqiang.com> X-Original-To: user2@liuqiang.com Delivered-To: user2@liuqiang.com Received: from LAPTOP-7NMG10E6 (unknown [192.168.6.1]) by mail.liuqiang.com (Postfix) with ESMTPS id 89D7560D8240 for <user2@liuqiang.com>; Fri, 6 May 2022 03:31:04 -0400 (EDT) Date: Fri, 6 May 2022 15:31:04 +0800 From: user1 <user1@liuqiang.com> To: user2 <user2@liuqiang.com> Subject: =?GB2312?B?suLK1MrVt6I=?= X-Priority: 3 X-Has-Attach: no X-Mailer: Foxmail 7.2.23.121[cn] Mime-Version: 1.0 Message-ID: <202205061531042523313@liuqiang.com> Content-Type: multipart/alternative; boundary="----=_001_NextPart321473501762_=----" This is a multi-part message in MIME format. ------=_001_NextPart321473501762_=---- Content-Type: text/plain; charset="GB2312" Content-Transfer-Encoding: base64 DQp1c2VyMSDE47rDo6ENCiAgICCxvtPKvP7E2sjdo7oyMDIyLjA1LjA2o6ENCg0KDQoNCnVzZXIx DQo= ------=_001_NextPart321473501762_=---- Content-Type: text/html; charset="GB2312" Content-Transfer-Encoding: quoted-printable <html><head><meta http-equiv=3D"content-type" content=3D"text/html; charse= t=3DGB2312"><style>body { line-height: 1.5; }body { font-size: 14px; font-= family: "Microsoft YaHei UI"; color: rgb(0, 0, 0); line-height: 1.5; }</st= yle></head><body>=0A<div><span></span><br></div>=0A<div>user1 =C4=E3=BA=C3= =A3=A1</div><div><span microsoft=3D"" yahei=3D"" ui";=3D"" font-size:=3D""= 14px;=3D"" color:=3D"" rgb(0,=3D"" 0,=3D"" 0);=3D"" background-color:=3D"= " rgba(0,=3D"" font-weight:=3D"" normal;=3D"" font-style:=3D"" normal;text= -decoration:=3D"" none;"=3D""> <span style=3D"font-size: 21px= ;">=B1=BE=D3=CA=BC=FE=C4=DA=C8=DD=A3=BA2022.05.06=A3=A1</span></span></div= ><div><span microsoft=3D"" yahei=3D"" ui";=3D"" font-size:=3D"" 14px;=3D""= color:=3D"" rgb(0,=3D"" 0,=3D"" 0);=3D"" background-color:=3D"" rgba(0,= =3D"" font-weight:=3D"" normal;=3D"" font-style:=3D"" normal;text-decorati= on:=3D"" none;"=3D""><span style=3D"font-size: 21px;"><br></span></span></= div><hr style=3D"width: 210px; height: 1px;" color=3D"#b5c4df" size=3D"1" = align=3D"left">=0A<div><span><div style=3D"MARGIN: 10px; FONT-FAMILY: verd= ana; FONT-SIZE: 10pt"><div>user1</div></div></span></div>=0A</body></html> ------=_001_NextPart321473501762_=------ [root@mail ~]#
通过以上测试确定电子邮件系统搭建成功。
特别说明:以上测试只测试最简单功能。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。