RHEL下SendMail修改發郵箱地址,rhelsendmail

來源:互聯網
上載者:User

RHEL下SendMail修改發郵箱地址,rhelsendmail

 

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設定檔

 

 

 

我們需要修改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的發送郵件有關

 

 

這個方法其實在實際環境中很少使用。畢竟修改主機名稱是一件非常麻煩的事情。

 

 

網上還有其它一些方法,但是我測試過多次都沒有成功,所以不在此羅列,有興趣的可以自行研究!

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.