1. 程式人生 > >Ubuntu14.04 sendmail郵件服務

Ubuntu14.04 sendmail郵件服務

1.安裝sendmail


[email protected]:~$ sudo apt-get install sendmail

[email protected]:~$ sudo apt-get install sendmail-cf
#幾個可選的包
squirrelmail              //提供webmail          
spamassassin          //提供郵件過濾  
mailman                   //提供郵件列表支援  
dovecot                   // 提供IMAP和POP接收郵件伺服器守護程序  
Ubuntu下使用最常用的mail功能,需要安裝mailutils,


[email protected]:~$ sudo apt-get install mailutils
#使用帶附件的功能,則還需要安裝sharutils,
[email protected]:~$ sudo apt-get install sharutils

2.配置sendmail服務


[email protected]:~$ sudo cp /etc/mail/sendmail.mc /etc/mail/sendmail.mc_backup
#備份配置檔案
[email protected]:~$ sudo vim /etc/mail/sendmail.mc
#找到如下行:

程式碼 
DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Port=smtp, Addr=127.0.0.1')dnl
 修改Addr=0.0.0.0  ,表明可以連線到任何伺服器。

[email protected]:/etc/mail$ sudo cp sendmail.cf sendmail.cf_backup
#做個備份

[email protected]:/etc/mail$ sudo m4 sendmail.mc > sendmail.cf

[email protected]:~$ sudo service sendmail restart
 * Restarting Mail Transport Agent (MTA) sendmail
   ...done.

[email protected]:~$ echo "hello" | mail -s "title" [email protected]

[email protected]:~$ tail -40 /var/log/mail.log 

Aug 23 16:30:10 wyj-virtual-machine sm-mta[3618]: STARTTLS=client, relay=126mx02.mxmail.netease.com., version=TLSv1/SSLv3, verify=FAIL, cipher=AES256-GCM-SHA384, bits=256/256
Aug 23 16:30:10 wyj-virtual-machine sm-mta[3618]: w7N8U9fu003616: to=<[email protected]>, ctladdr=<[email protected]> (1000/1000), delay=00:00:01, xdelay=00:00:01, mailer=esmtp, pri=120350, relay=126mx02.mxmail.netease.com. [220.181.15.202], dsn=5.0.0, stat=Service unavailable
Aug 23 16:30:10 wyj-virtual-machine sm-mta[3618]: w7N8U9fu003616: w7N8UAfu003618: DSN: Service unavailable
Aug 23 16:30:10 wyj-virtual-machine sm-mta[3618]: w7N8UAfu003618: to=<[email protected]>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent

#根據relay=126mx02.mxmail.netease.com. [220.181.15.202], dsn=5.0.0, stat=Service unavailable ...stat=Sent  郵件已經發出去但是被拒絕

“localhost.localdomain”將被許多郵件伺服器自動拒絕。

更換hostname方法:
1、編輯/etc/sysconfig/network,更換檔案中的hostnmae。
2、把hostname寫入/etc/hosts
3、執行hostname 域名立即生效

#改了個域名 hostname wyj.com

[email protected]:~$ echo "hello" | mail -s "title" [email protected]
[email protected]:~$ tail -4 /var/log/mail.log 
Aug 24 10:50:49 wyj sm-mta[4696]: w7O2omOj004696: from=<[email protected]>, size=314, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Aug 24 10:50:49 wyj sendmail[4695]: w7O2omqx004695: to=<[email protected]>, [email protected] (1000/1000), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30084, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (w7O2omOj004696 Message accepted for delivery)
Aug 24 10:50:50 wyj sm-mta[4698]: STARTTLS=client, relay=126mx03.mxmail.netease.com., version=TLSv1/SSLv3, verify=FAIL, cipher=AES256-GCM-SHA384, bits=256/256
Aug 24 10:50:52 wyj sm-mta[4698]: w7O2omOj004696: to=<[email protected]>, ctladdr=<[email protected]> (1000/1000), delay=00:00:03, xdelay=00:00:03, mailer=esmtp, pri=120314, relay=126mx03.mxmail.netease.com. [220.181.15.193], dsn=2.0.0, stat=Sent (Mail OK queued as mx13,wcmowADHzFGPcn9bQhD0Fw--.59342S3 1535079058) 
#Mail OK 傳送成功

 

常用傳送郵件方式如下:

    1.如何寫一般的郵件: mail [email protected]  Cc 編輯抄送物件,Subject:郵件主題,輸入回車,郵件正文後,按Ctrl-D結束

    2.快速傳送方式: echo “郵件正文” | mail -s 郵件主題 [email protected]

    3.以檔案內容作為郵件正文來發送: mail -s test [email protected] < test.txt

    4.傳送帶附件的郵件: uuencode 附件名稱 附件顯示名稱 | mail -s 郵件主題 傳送地址

       例如: uuencode test.txt test.txt | mail -s Test [email protected]

 

參考部落格:https://blog.csdn.net/xin_yu_xin/article/details/45115723

https://blog.csdn.net/qq_32126633/article/details/76020846

https://www.centos.bz/2012/06/dsn-service-unavailable/

https://www.centos.bz/2012/06/dsn-service-unavailable/