Ubuntu14.04 sendmail邮件服务

1.安装sendmail


wyj@wyj-virtual-machine:~$ sudo apt-get install sendmail

wyj@wyj-virtual-machine:~$ sudo apt-get install sendmail-cf
#几个可选的包
squirrelmail              //提供webmail          
spamassassin          //提供邮件过滤  
mailman                   //提供邮件列表支持  
dovecot                   // 提供IMAP和POP接收邮件服务器守护进程  
Ubuntu下使用最常用的mail功能,需要安装mailutils,

wyj@wyj-virtual-machine:~$ sudo apt-get install mailutils
#使用带附件的功能,则还需要安装sharutils,
wyj@wyj-virtual-machine:~$ sudo apt-get install sharutils

2.配置sendmail服务


wyj@wyj-virtual-machine:~$ sudo cp /etc/mail/sendmail.mc /etc/mail/sendmail.mc_backup
#备份配置文件
wyj@wyj-virtual-machine:~$ 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  ,表明可以连接到任何服务器。

wyj@wyj-virtual-machine:/etc/mail$ sudo cp sendmail.cf sendmail.cf_backup
#做个备份

wyj@wyj-virtual-machine:/etc/mail$ sudo m4 sendmail.mc > sendmail.cf

wyj@wyj-virtual-machine:~$ sudo service sendmail restart
 * Restarting Mail Transport Agent (MTA) sendmail
   ...done.
wyj@wyj-virtual-machine:~$ echo "hello" | mail -s "title" [email protected]

wyj@wyj-virtual-machine:~$ 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=<wyj@wyj-virtual-machine> (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=<wyj@wyj-virtual-machine>, 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

wyj@wyj:~$ echo "hello" | mail -s "title" [email protected]
wyj@wyj:~$ 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/

猜你喜欢

转载自blog.csdn.net/caijiwyj/article/details/82014371
今日推荐