1. 程式人生 > >linux學習-mail傳送郵件(mail不能發郵件)

linux學習-mail傳送郵件(mail不能發郵件)

主機:centos 7 ,

安裝sendmail,啟動sendmail,一般就可以了,但是有些同學為什麼不行,就是啟不動出現如下的情況!那現在如何解決。

yum install sendmail
systemctl start sendmail.service
systemctl status sendmail.service
● sendmail.service - Sendmail Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/sendmail.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2016-05-08 12:22:58 CST; 1min 33s ago
  Process: 9727 ExecStart=/usr/sbin/sendmail -bd $SENDMAIL_OPTS $SENDMAIL_OPTARG (code=exited, status=0/SUCCESS)
  Process: 9722 ExecStartPre=/etc/mail/make aliases (code=exited, status=0/SUCCESS)
  Process: 9720 ExecStartPre=/etc/mail/make (code=exited, status=0/SUCCESS)
 Main PID: 9730 (sendmail)
   CGroup: /system.slice/sendmail.service
           └─9730 sendmail: accepting connection

May 08 12:21:58 iZ28xev9g2sZ systemd[1]: Starting Sendmail Mail Transport Agent...
May 08 12:21:58 iZ28xev9g2sZ sendmail[9727]: My unqualified host name (iZ28xev9g2sZ) unknown; sleeping for retry
May 08 12:22:58 iZ28xev9g2sZ sendmail[9727]: unable to qualify my own domain name (iZ28xev9g2sZ) -- using short name
May 08 12:22:58 iZ28xev9g2sZ systemd[1]: PID file /run/sendmail.pid not readable (yet?) after start.
May 08 12:22:58 iZ28xev9g2sZ sendmail[9730]: starting daemon (8.14.7): 
[email protected]
:00:00 May 08 12:22:58 iZ28xev9g2sZ systemd[1]: Started Sendmail Mail Transport Agent.
解決方法:其實就是你的主機沒有設定hostname

mail傳送郵件,預設呼叫的是sendmail,sendmail傳送郵件,必須設定hostname,而hostname不能是一串字串,而必須是格式正確的域名,例如mail.tome178.com

所以我們的解決方法是修改hostname,一種是臨時的,一種是永久的

一般我們可以設定臨時的

hostname mail.tome178.com

永久的修改/etc/sysconfig/network

hostname=mail.tome178.com //主機名(沒有這行?那就新增這一行吧) 
然後執行

hostname mail.tome178.com

然後重啟sendmail就可以傳送郵件了

● sendmail.service - Sendmail Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/sendmail.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2016-05-08 12:39:48 CST; 16min ago
  Process: 9939 ExecStart=/usr/sbin/sendmail -bd $SENDMAIL_OPTS $SENDMAIL_OPTARG (code=exited, status=0/SUCCESS)
  Process: 9933 ExecStartPre=/etc/mail/make aliases (code=exited, status=0/SUCCESS)
  Process: 9932 ExecStartPre=/etc/mail/make (code=exited, status=0/SUCCESS)
 Main PID: 9942 (sendmail)
   CGroup: /system.slice/sendmail.service
           └─9942 sendmail: accepting connections

May 08 12:41:12 mail.tome178.com sendmail[9965]: u484fBCq009965: from=<
[email protected]
>, si....1] May 08 12:41:13 mail.tome178.com sendmail[9967]: STARTTLS=client, relay=163mx01.mxmail.netease.co...256 May 08 12:41:14 mail.tome178.com sendmail[9967]: STARTTLS=client, relay=163mx03.mxmail.netease.co...256 May 08 12:41:14 mail.tome178.com sendmail[9967]: u484fBCq009965: to=<[email protected]>, ctladdr=<...74) May 08 12:41:21 mail.tome178.com sendmail[9971]: u484fKXx009971: from=<[email protected]>, si....1] May 08 12:41:21 mail.tome178.com sendmail[9973]: STARTTLS=client, relay=mx3.qq.com., version=TLSv...128 May 08 12:41:24 mail.tome178.com sendmail[9973]: u484fKXx009971: to=<[email protected]>, ctladdr=<r...s ) May 08 12:54:08 mail.tome178.com sendmail[9988]: u484s8IS009988: from=<[email protected]>, si....1] May 08 12:54:09 mail.tome178.com sendmail[9990]: STARTTLS=client, relay=mx3.qq.com., version=TLSv...128 May 08 12:54:09 mail.tome178.com sendmail[9990]: u484s8IS009988: to=<[email protected]>, ctladdr=<r...s ) Hint: Some lines were ellipsized, use -l to show in full.