返回文章列表文章索引阅读全文
STARBLOG / 阅读手记
系统配置

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

曦远 (DealiAxy)约 15 分钟
目录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:

DomainTypeRecord
mailA127.0.0.1

(2) Add (or modify) your domain's MX record in the following format:

DomainTypeRecord
@MXdeali.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`

Log Level Explanation

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

http://www.5dmail.net/ Sendmail official site All about email sending Viewing email headers

_EOF_

Linux Configure Sendmail for Email Service

本文作者:
程序设计实验室
版权声明:
本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

相关文章

Linux设置系统邮件转发到指定邮箱

前言 在Linux的操作中,有的时候每敲一下回车,就出来You have new mail in /var/spool/mail/root的提示,究竟是为什么呢? Linux 系统经常会自动发出一些邮件来提醒用户系统中出了哪些问题(收件箱位置:/var/mail/)。可是这些邮件都是发送给 root 用户的。出于系统安全考虑,通常不建议大家直接使用 root 帐户进行日常操作。所以要想点办法来让系

2025-10-27 · 系统配置 · 约 1 分钟

Debian配置默认不开启图形界面

前言 Linux的图形界面实在是太耗资源了,同时开几个虚拟机感觉已经hold不住了,赶紧把这些Linux服务器的图形界面都关掉。 CLI:command Line Interface,命令行界面。 现在的Linux发行版默认登陆界面几乎都是默认为GUI界面,如果按照旧版本的修改inittab文件,在一些比较新的版本是没有这个文件的(Linux的启动服务机制发生改变) 修改Grub配置文件 打开gr

2025-10-27 · 系统配置 · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…