设为首页 加入收藏

TOP

RHEL下SendMail修改发邮箱地址
2017-10-13 10:37:15 】 浏览:5141
Tags:RHEL SendMail 修改 邮箱 地址

 

RHEL(Oracle Linxu/CentOS)系统下,如果使用sendmail发送邮件,如果不特殊设置,一般发件箱地址为user@hostname,例如,hostname为DB-Server.localdomain,在root用户下使用下面命令发送一封邮件:

 

[root@DB-Server ~]# hostname -f
 
DB-Server.localdomain
 
[root@DB-Server ~]# echo "hello,it is a test email from kerry" | mail -s "Hello,Welcome your test email" konglb@xxx.com

 

此时收件箱地址root@DB-Server.localdomain,那么如何修改发件箱地址呢?

 

 

方法1:使用sendmail的参数f,在参数f后指定发件箱。

 

 
[root@DB-Server ~]# echo "hello,it is a test email from kerry" | mail -s "Hello,Welcome your test email" konglb@xxxx.com -- -f DB-Server@mydba.com

  

此时测试,你就会发现发件箱地址为DB-Server@mydba.com,当然这里你可以对发件地址进行任意设置。这个是最好、最快捷的方法。

 

 

方法2:修改sendmail.cf配置文件

 

 

clip_image001

 

我们需要修改sendmail.mc中5个地方,如上截图所示, dnl表示选项被注释, 我们需要取消4处注释,注释掉一处地方

 

MASQUERADE_AS(domain.com)dnl

 

FEATURE(masquerade_envelope)dnl

 

FEATURE(masquerade_entire_domain)dnl

 

MASQUERADE_DOMAIN(domain.com)dnl

 

dnl EXPOSED_USER(`root')dnl

 

 

MASQUERADE_AS(`mydba.com')dnl

dnl #

dnl # masquerade not just the headers, but the envelope as well

dnl #

FEATURE(masquerade_envelope)dnl

dnl #

dnl # masquerade not just @mydomainalias.com, but @*.mydomainalias.com as well

dnl #

FEATURE(masquerade_entire_domain)dnl

dnl #

dnl MASQUERADE_DOMAIN(localhost)dnl

dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl

dnl MASQUERADE_DOMAIN(mydomainalias.com)dnl

MASQUERADE_DOMAIN(mydba.com)dnl

MAILER(smtp)dnl

 

dnl EXPOSED_USER(`root')dnl

 

 

[root@DB-Server ~]# m4 /etc/mail/sendmail.mc  >  /etc/mail/sendmail.cf
/etc/mail/sendmail.mc:10: m4: cannot open `/usr/share/sendmail-cf/m4/cf.m4': No such file or directory

 

出现上面错误,是因为没有安装sendmail-cf组件,安装了sendmail-cf组件后,就不会出现上面错误

 

[root@DB-Server tmp]# rpm -ivh sendmail-cf-8.13.8-8.el5.x86_64.rpm 
warning: sendmail-cf-8.13.8-8.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing...                ########################################### [100%]
   1:sendmail-cf            ########################################### [100%]
[root@DB-Server tmp]# 
[root@DB-Server mail]# m4 /etc/mail/sendmail.mc  >  /etc/mail/sendmail.cf

 

一般是配置/etc/mail/sendmail.mc文件,然后通过上面命令生成sendmail.cf文件,但是要注意,不要将之前的一些配置信息给覆盖了,例如SMTP服务器等。另外,重新生成配置文件后必须重启sendmail服务,否则配置不会生效

 

[root@DB-Server mail]# service sendmail restart
Shutting down sm-client: [  OK  ]
Shutting down sendmail: [  OK  ]
Starting sendmail: [  OK  ]
Starting sm-client: [  OK  ]

 

此时在不指定发件人地址的时候,发件人地址为root@mydba.com 或 oracle@mydba.com 。 邮件前缀为当前用户名.

 

 

3:修改主机名,主机名和sendmail的发送邮件有关

 

 

这个方法其实在实际环境中很少使用。毕竟修改主机名是一件非常麻烦的事情。

 

 

网上还有其它一些方法,但是我测试过多次都没有成功,所以不在此罗列,有兴趣的可以自行研究!

 

 

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇原创:LNMP架构部署个人博客网站 .. 下一篇linux中必会的目录

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目