Linux Configure Sendmail for Email Service
Preface Due to development needs, I set up a wiki system and utilized email subscriptions, which led me to research various methods for sending emails. Installation There’s nothing special to say; first, install the necessary components. apt install sendmail-bin apt install sendmail apt install sendmail-cf #Configuration tool Configuring sendmail By default, sendmail is set to send emails from local users to local users. To enable sending to the entire Internet, you need to modify the configuration: Modify se
目录19 个章节
Preface
Due to development needs, I built a wiki系统 (wiki system) and used email subscription, so I researched various methods for sending emails.
Installation
There's nothing much to say, just install the necessary components first.
apt install sendmail-bin
apt install sendmail
apt install sendmail-cf # Configuration tool
Configure sendmail
sendmail is by default set up to send emails only locally on the machine. Therefore, it needs to be modified to allow sending emails across the entire Internet:
Modify the sendmail configuration macro file, located at /etc/mail/sendmail.mc
Find
DAEMON_OPTIONS('Family=inet, Name=MTA-v4, Port=smtp, Addr=127.0.0.1')dnl
Change Addr=127.0.0.1 to Addr=0.0.0.0, which allows connections to any server.
Save the modified file, then back up the configuration file:
cd /etc/mail
mv sendmail.cf sendmail.cf~
Next, generate a new configuration file:
m4 sendmail.mc > sendmail.cf
Restart sendmail for the changes to take effect.
Configuring Domain Names
Configuring sendmail to use a legitimate domain name involves two steps: modifying sendmail's configuration file and adding the domain's MX record.
sendmail can directly use the -r account@domain.com parameter to send emails from any source address. However, most mainstream email providers will compare the source address with the reverse DNS resolution of the IP. If the resolution fails or the resolved IP doesn't match, the email might be classified as SPAM or, in worse cases, be outright rejected.
The MX Record (Mail Exchanger Record) is primarily used for receiving emails. When delivering a new email, the system queries the MX record of the recipient's domain and uses the IP address obtained from the MX record to proceed with delivery. Additionally, email providers often compare the source address with the MX record when receiving emails, using it as one of the criteria for identifying spam.
Step 1: Add the Domain
(1) Add the domain to the local-host-names file
Open: /etc/mail/local-host-names
Add:
deali.cn
(2) Modify the submit.cf file
Open: vi /etc/mail/submit.cf, find the line #Dj$w.Foo.COM, and modify it to
Djdeali.cn
Attention! It must be in the format of Dj + Domain!
At this point, the sendmail email naming configuration is complete. Restart sendmail to apply the configuration.
Step 2: Add Domain MX Records
Navigate to the page where you can modify your domain information (this page varies by domain registrar). The changes may take up to 24 hours to take effect, depending on the registrar.
(1) Add an A record for the mail subdomain, pointing directly to your mail server's static IP address:
| Domain | Type | Record |
|---|---|---|
| A | 127.0.0.1 |
(2) Add (or modify) your domain's MX record in the following format:
| Domain | Type | Record |
|---|---|---|
| @ | MX | deali.cn |
(3) Use nslookup to verify that the MX record correctly resolves to your mail server.
nslookup
> set q=mx
> deali.cn
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
deali.cn mail exchanger = 5 deali.cn.
Authoritative answers can be found from:
Email Send Test
Enter the following command:
sendmail -t <<EOF
A > prompt will appear, then input the content in the format below (press Enter after each line):
From:Mail test <test@yourdomain.com>
To:xxxx@qq.com
Subject:Test
test
EOF
See the question
Relaying denied(Relaying denied)
When the error 550 5.7.1 <xxx@163.com>... Relaying denied. IP name lookup failed [192.168.1.133] occurs, the reason is that sendmail is being used as a mail relay. To resolve this, you need to add the client's IP address to the access configuration file.
Open: /etc/mail/access, and add the following:
Connect:Client_IP RELAY
Then, regenerate the access permissions database:
cd /etc/mail/
makemap hash access.db < access
Sent Emails Being Identified as Spam by Other MTAs
Set up domain pointing (link to the previous section) and add SPF records Operation Tutorial Also, pay attention to controlling the email sending frequency.
Where to Check Sendmail Logs?
Log location: /var/log/maillog
To adjust the log level (verbosity): modify the configuration file define(confLOG_LEVEL',16')dnl(default is9), or specify when calling the command: sendmail -O LogLevel=14`
What do sendmail logs mean?
Note that sendmail does not guarantee that the sent email will always be delivered to the recipient, so the information in the logs is only the connection information fed back by the receiving end's MTA.
For the specific format, feel free to read through it—–sendmail log format
Sendmail Performance Parameters
http://www.5dmail.net/html/2008-4-27/200842733006.htm
Some related websites and articles
http://www.5dmail.net/ Sendmail official site All about email sending Viewing email headers
_EOF_
Linux Configure Sendmail for Email Service
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
给你的Deepin系统换主题~
我现在的桌面: 因为美国封锁然后华为电脑用上Deepin系统的事情,Deepin系统最近名声大噪,其实Deepin本来的界面就很好看,号称打造最适合国人的系统不是盖的。 不过Deepin有一个坏处,就是默认主题的标题栏太大了…… 太占空间。所以我们要换主题折腾一下。 Deepin的桌面是Qt写的,所以首先要换KDE主题,然后再安排一下GTK3的主题,在Deepin系统设置里面换的主题就是GTK的,
2025-10-01 · 系统配置 · 约 1 分钟
Ubuntu-18-04-开启托盘图标点击最小化
前言 Ubuntu的托盘挺好看的,美中不足的就是点击一个打开的应用图标不能像Windows那样最小化。 操作 gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize' 截图
2025-10-27 · 系统配置 · 约 1 分钟
Linux终端输入密码显示星号
Linux默认密码星号?这体验真不错。一行sudoers配置搞定,真就有人非要用脚本整这些。关闭?那不是自讨没趣吗。
2025-10-01 · 系统配置 · 约 1 分钟
Ubuntu-18-04-修改登录界面背景图
前言 Ubuntu 18.04用了一段时间了,在Gnome桌面的加持下,兔子 18.04 的颜值还不错,加上自己搭配了几套GTK主题,简直美滋滋,唯一美中不足的就是,Ubuntu的登录管理器换成GDM之后,登录界面背景没办法修改了,这怎么行呢,于是经过一番折腾,有了本文。 首先,准备一张图片 图片的尺寸呢,根据你的屏幕分辨率确定咯。 然后把图片放到/usr/share/backgrounds/目录
2025-10-27 · 系统配置 · 约 1 分钟
讨论
共 0 条加载评论中…