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 许可协议。转载请注明出处!
相关文章
配置MariaDB数据库服务端远程访问
操作步骤 开启远程访问权限 连接MariaDB数据库,执行以下命令开启远程访问。 grant all privileges on *.* to 'root'@'192.168.248.248' identified by 'password'; flush privileges; 如果需要任意IP地址访问,就把IP地址换成%。 修改配置文件 在网络上能搜索到的资料都只说了第一点,然而亲测之后并没有
2025-10-27 · 系统配置 · 约 1 分钟
在Nginx上配置https加密服务器
前言 最近开发微信小程序需要使用Https,于是折腾了一番。 超简单步骤 1. 申请SSL证书 一般云服务器提供商就会提供这种服务,我在腾讯云上申请了,十分钟就完成了。 2. 上传证书 上传到一个文件夹里面 3. 配置nginx 网络上的资料都是直接修改 /etc/nginx/nginx.conf 这个文件。 不过我的服务器上这个文件里头没有 server 这个节点可以配置。 因此需要修改 /et
2025-10-27 · 系统配置 · 约 1 分钟
linux配置sendmail发邮件服务
前言 因为开发需要,搞了个wiki系统,并且用到了邮件订阅,所以研究了一番发送邮件的方法。 安装 没什么好说的,先安装必要组件。 apt install sendmail-bin apt install sendmail apt install sendmail-cf #配置工具 配置sendmail sendmail默认是本机用户发送给本机,所以需要修改可以发送到整个Internet: 修改se
2025-10-27 · 系统配置 · 约 1 分钟
Ubuntu-18-04-开启托盘图标点击最小化
前言 Ubuntu的托盘挺好看的,美中不足的就是点击一个打开的应用图标不能像Windows那样最小化。 操作 gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize' 截图
2025-10-27 · 系统配置 · 约 1 分钟
讨论
共 0 条加载评论中…