如何配置Sendmail虚拟邮件映射?

Sendmail

1 前言

一个问题,一篇文章,一出故事。
笔者需要将邮件“will@mail03.cmdschool.org”自动转发到“will@mail01.cmdschool.org”,于是想到使用虚拟邮件映射功能。

2 最佳实践

2.1 配置mail01主机

请参阅以下文档配置标准邮件投递主机mail01(需要其他功能也可以配置),请注意可以不配置mail02,

如何部署Sendmail?

2.2 配置mail03主机

2.2.1 配置主机名称

hostnamectl set-hostname mail03.cmdschool.org

2.2.2 确保chronycd启动并正确配置

systemctl status chronyd.service
grep ^pool /etc/chrony.conf

最后一条命令显示如下,

pool 2.rhel.pool.ntp.org iburst

注:如果内网有NTP服务器,可将以上NTP服务器的域名换成内网的NTP服务器(需要重启服务配置生效才生效)

2.2.3 安装常用软件包

In mail03

yum install -y vim

2.2.4 安装软件包

In mail03

yum install -y sendmail sendmail-cf m4

2.2.5 启动与设置自启动并获取状态

In mail03

systemctl start sendmail.service
systemctl enable sendmail.service
systemctl status sendmail.service
systemctl start saslauthd.service
systemctl enable saslauthd.service
systemctl status saslauthd.service

服务启动后,建议你使用如下命令查看端口倾听状态,

netstat -antp | grep "sendmail"

可见如下显示,

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      30320/sendmail: acc

2.2.6 修改服务器配置

In mail03

cp /etc/mail/sendmail.mc /etc/mail/sendmail.mc.default
vim /etc/mail/sendmail.mc

修改如下配置使倾听端口允许对外服务,

DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

如果需要使配置生效,还需执行如下操作,

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

以上配置完成后,我们使用如下命令配置虚拟邮件映射,

cp /etc/mail/virtusertable /etc/mail/virtusertable.default
vim /etc/mail/virtusertable

修改如下配置使倾听端口允许对外服务,

will@mail03.cmdschool.org will@mail01.cmdschool.org

配置文件修改完毕后,还需运行如下命令更新配置,

makemap hash /etc/mail/virtusertable.db < /etc/mail/virtusertable

2.2.7 重启服务使配置生效

In mail03

systemctl restart sendmail.service

服务重启后倾听端口地址有所变化,

netstat -antp | grep "sendmail"

可见如下显示,

tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      3978/sendmail: acce

2.3 测试Sendmail

2.3.1 安装软件包

In mail03,

yum install -y mailx

2.3.2 本地命令测试邮件发送

In mail03,

echo 'it is only a test' | mail -s "test eamil"  will@mail03.cmdschool.org

2.3.3 使用命令行阅读邮件

In mail01,

su - will

以上命令切换用户身份,然后使用如下命令查看邮件,

mailx

操作向导如下,

Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/will": 1 message 1 new
>N  1 root                  Tue Jul 27 04:47  25/1129  "test eamil"
& type 1
Message  1:
From root@mail03.cmdschool.org  Tue Jul 27 04:47:04 2021
Return-Path: 
From: root 
Date: Tue, 27 Jul 2021 04:47:04 -0400
To: will@mail03.cmdschool.org
Subject: test eamil
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
Status: R

it is only a test

& delete 1
& quit

参阅文档
=================
Sendmail官方主页
————
https://www.proofpoint.com/us/products/email-protection/open-source-email-solution

Sendmail使用文档
——————–
http://mirror.internode.on.net/pub/ldp/en/solrhe/chap22sec176.html
http://etutorials.org/Linux+systems/red+hat+linux+bible+fedora+enterprise+edition/Part+IV+Red+Hat+Linux+Network+and+Server+Setup/Chapter+19+Setting+Up+a+Mail+Server/Configuring+sendmail/
https://docs.oracle.com/cd/E56344_01/html/E53883/index.html
https://baike.baidu.com/item/sendmail/2250367?fr=aladdin
https://www.oreilly.com/library/view/sendmail-cookbook/0596004710/ch01.html
https://blog.csdn.net/z59d8m6e40/article/details/72871485

镜像地址
—————
https://www.proofpoint.com/us/sendmail/list-of-mirrors

下载地址
———————
https://ftp.sendmail.org/
http://ftp.ntua.gr/pub/net/mail/sendmail/

github
————–
https://en.wikipedia.org/wiki/Sendmail

错误信息“Deferred: 403 4.7.0 TLS handshake failed.”的处理
————————-
https://bobcares.com/blog/how-to-fix-error-403-4-7-0-tls-handshake-failed/

没有评论

发表回复

Sendmail
如何解决SendMail SSL错误?

1 前言 一个问题,一篇文章,一出故事。 笔者最近SendMail服务器更换下一跳的smtp中继服务 …

Sendmail
如何解决Sendmail队列负载过高报错?

1 前言 一个问题,一篇文章,一出故事。 今天某项目组反馈邮件无法发送,由于他们使用的是专用的Sen …

Sendmail
如何根据域名指定Sendmail邮件的下一跳地址?

1 前言 一个问题,一篇文章,一出故事。 笔者想要根据域名指定邮件的下一跳地址,以便邮件可以被送到特 …