(1)linux
直接使用shell当编辑器
shell
# mail -s "Hello from linuxde.net by shell" admin@linuxde.net hello,this is the content of mail. welcome to www.linuxde.net
第一行是输入的命令,-s表示邮件的主题,后面的admin@linuxde.net则是邮件的接收人,输入完这行命令后回车,会进入邮件正文的编写,咱们能够输入任何文字,好比上面的两行。当邮件正文输入完成后,须要按CTRL+D结束输入,此时会提示你输入Cc地址,即邮件抄送地址,没有直接回车就完成了邮件的发送。
使用管道进行邮件发送编辑器
echo "hello,this is the content of mail.welcome to www.linuxde.net" | mail -s "Hello from linuxde.net by pipe" admin@linuxde.net this
使用管道直接敲入这行命令便可完成邮件的发送,其中echo后的是邮件正文。 spa
使用文件进行邮件发送 .net
mail -s "Hello from linuxde.net by file" admin@linuxde.net < mail.txt code
使用上面的命令后,咱们就能够把mail.txt文件的内容做为邮件的内容发送给admin@linuxde.net了。 blog
使用上述三种方式均可以给外部邮箱进行邮件发送,但由于前面2中都是直接在shell中敲入邮件内容,所以没法输入中文,即便咱们使用粘贴的方式输入了中文,那么收到的邮件也是乱码的。但第3种方式,咱们能够在window下编辑好邮件内容后,放到linux下,再进行发送,这样就能够正常发送中文了。不过目前邮件的中文标题暂时没有找到解决办法。ip
由于mail程序自己就是调用sendmail来进行邮件发送的,所以咱们能够在mail命令中使用sendmail的参数进行配置,好比我想使用特定的发件人发送邮件,能够使用以下命令:get
mail -s "Hello from linuxde.net with sender" admin@linuxde.net -- -f user@linuxde.net < mail.txt
使用-- -f user@linuxde.net,能指定邮件的发件人是 “user@linuxde.net”。
上面的命令中,咱们使用了–- -f user@linuxde.net这样的参数,这是sendmail的选项,其中-f表示邮件的发送人邮件地址。
来自: http://man.linuxde.net/mail