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...
目录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
_EOF_
Linux Configure System Email Forwarding to Designated Mailbox
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
Ubuntu-16-04-安装配置Docker
安装相关包 $ sudo apt-get update # 先更新一下软件源库信息 $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common 添加软件仓库 官方仓库 # 添加 Docker 官方的 GPG 密钥(为了确认所下载
2025-10-27 · 系统配置 · 约 1 分钟
Linux安装zsh并使用oh-my-zsh配置
安装zsh sudo apt install zsh 配置 oh my zsh curl sh -c $(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh) wget sh -c $(wget https://raw.github.com/robbyrussell/oh-my-zsh/m
2025-10-27 · 系统配置 · 约 1 分钟
小心误关了NAS服务器!修改Linux的电源键功能
NAS居然离线关机了?电源键被傻逼系统接管了。改改`logind.conf`让这玩意忽略电源键,省得误操作重启关机。谁用谁知道,别真当NAS是玩具。
2025-10-27 · 系统配置 · 约 1 分钟
给VMware里的Linux虚拟机配置静态ip
前言 最近用VMware的时候是使用桥接方式,不知道是路由的问题还是其他,路由器里面没有显示虚拟机的连接,虽然虚拟机和主机都在路由器里分配了不同的IP地址,但是每次resume之后虚拟机的IP地址总是变,很麻烦。 VMware设置 把下面这个勾去掉。 然后点击Nat Settings。 记录网关。 虚拟机设置。把网络改成这个VMnet8。 Linux系统中配置静态IP Debian nano /e
2025-10-27 · 系统配置 · 约 1 分钟
讨论
共 0 条加载评论中…