centos下发送邮件

在/etc/mail.rc文件下添加如下内容

格式一:

set [email protected] smtp=smtp.163.com:25 [email protected] smtp-auth-password=password smtp-auth=login

格式二:

set from=187xxxxxxxx@163.com

set smtp=smtp.163.com:25

set smtp-auth-user=187xxxxx@163.com

set smtp-auth-password=password

set smtp-auth=login

#from是发送的邮件地址

#smtp是发生的外部smtp服务器的地址

#smtp-auth-user是外部smtp服务器认证的用户名

#smtp-auth-password是外部smtp服务器认证的用户密码

#smtp-auth是邮件认证的方式

发送邮件的格式

直接使用shell当编辑器

mail -s "Hello from yh by shell" 1872xxxxxxx@163.com

hello,this is the content of mail.

welcome to yyyyy

第一行是输入的命令,-s表示邮件的主题,后面的[email protected]则是邮件的接收人,输入完这行命令后回车,会进入邮件正文的编写,我们可以输入任何文字,比如上面的两行。当邮件正文输入完成后,需要按CTRL+D结束输入,此时会提示你输入地址,即邮件抄送地址,没有直接回车就完成了邮件的发送。

使用管道进行邮件发送

echo "hello,this is the content of mail" | mail -s "Hello from yyyy by pipe" [email protected]

使用管道直接敲入这行命令即可完成邮件的发送,其中echo后的是邮件正文。

 

使用文件进行邮件发送

mail -s "Hello from yyy by file" [email protected] < mail.txt

使用上面的命令后,我们就可以把mail.txt文件的内容作为邮件的内容发送给[email protected]了。

使用上述三种方式都可以给外部邮箱进行邮件发送,但因为前面2中都是直接在shell中敲入邮件内容,因此无法输入中文,即使我们使用粘贴的方式输入了中文,那么收到的邮件也是乱码的。但第3种方式,我们可以在window下编辑好邮件内容后,放到linux下,再进行发送,这样就可以正常发送中文了。不过目前邮件的中文标题暂时没有找到解决办法。

猜你喜欢

转载自www.cnblogs.com/HByang/p/9131927.html