曦远 (DealiAxy)一份私人的文字刊物

StarBlog
返回文章列表折页手记阅读全文
系统配置

Linux Configure System Email Forwarding to Designated Mailbox

Preface In Linux operations, sometimes every time you press Enter, the prompt "You have new mail in /var/spool/mail/root" appears. What exactly is the reason for this? The Linux system often automatically sends out some emails to alert users about issues in the system (inbox location: /var/mail/). However, these emails are all sent to the root user. Considering system security, it is generally not recommended for everyone to directly use the root account for daily operations. Therefore, we need to find a way to let the system...

曦远 (DealiAxy)约 8 分钟
目录6 个章节

Preface

In Linux operations, sometimes after pressing Enter, the message "You have new mail in /var/spool/mail/root" appears. Why does this happen? Linux systems often automatically send emails to notify users about issues within the system (mailbox location: /var/mail/). However, these emails are all sent to the root user. For system security reasons, it is generally not recommended to use the root account for daily operations. Therefore, you need to find a way to either forward the emails sent to the root user to a designated external mailbox or simply disable this service.

Disabling the sendmail Service

This method introduces a way to disable the sendmail service without actually shutting it down.

echo “unset MAILCHECK” >> /etc/profile
source /etc/profile

To disable the functionality of sendmail:

chmod 0 /usr/sbin/sendmail
mv /usr/sbin/sendmail /usr/sbin/sendmail.bak
ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail

Clear the /var/spool/mail/root log

cat /dev/null > /var/spool/mail/root
cat /dev/null>;/var/spool/mail/root

Forward root Emails to Your Own Mailbox

Method 1

Modify this file

/etc/log.d/logwatch.conf
添加 MailTo = root,xxx@xxx.com

Method 2

Modify /etc/aliases
Add root: xxx@xxx.com

Note: It seems that if the recipient is set to be in the same domain as the host, the email cannot be sent successfully. For example, if the local machine's email is moper.me, sending to this address will fail, while sending to other email addresses will succeed.

Regarding "/etc/aliases":

When sendmail receives a message addressed to a specific user, it delivers the message to another user based on the contents of the /etc/aliases file. This feature allows the creation of a user that is only valid within the mail system. For instance, this function is used for mailing lists. In a mailing list, we might create an address like redlinux@link.ece.uci.edu, but there is no actual user named "redmail". In effect, the aliases file directs all mail sent to this user to the mailing list processing program, which is responsible for distributing the messages.

The /etc/aliases file is a text document, but sendmail requires a binary format file, /etc/aliases.db. The purpose of the newaliases command is to convert /etc/aliases into a database file that sendmail can understand:

[root@centos ~]# newaliases

Mail for users other than root can be forwarded by creating a .forward file in their /home/ directory:

//somebody
other1
other2

Setting the file permissions to 600 achieves the same effect. However, the .forward file can be maintained by the user themselves, whereas the aliases file can only be modified by the administrator.

To set it up, simply add the forwarding destination to the ~/.forward file.

References

http://moper.me/linux-you-have-new-mail-in.html

_EOF_

Linux Configure System Email Forwarding to Designated Mailbox

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

相关文章

内存不够用?在Linux上使用swapfile配置交换空间

前言 几个月前我还兴高采烈写了篇文章说给笔记本升级了内存配置,从乞丐版的4G一跃成为16G高富帅,然而,这几个月来我备受电脑死机的折磨,我现在有理由怀疑我可能买了假的内存条,于是没有办法,只能换回原厂的4G内存条,~~(然后准备赚部台式机)~~,问题不大。 换上4G内存条之后效果显著,只开了一个谷歌浏览器,内存占用就已经到了80%了,JB家的IDE是决计不敢再用了,可是这样还是难以满足系统对内存空

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

Ubuntu-18-04-修改登录界面背景图

前言 Ubuntu 18.04用了一段时间了,在Gnome桌面的加持下,兔子 18.04 的颜值还不错,加上自己搭配了几套GTK主题,简直美滋滋,唯一美中不足的就是,Ubuntu的登录管理器换成GDM之后,登录界面背景没办法修改了,这怎么行呢,于是经过一番折腾,有了本文。 首先,准备一张图片 图片的尺寸呢,根据你的屏幕分辨率确定咯。 然后把图片放到/usr/share/backgrounds/目录

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

讨论

共 0 条

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

加载评论中…