复制代码代码如下: mail -s “this is a title” bbmonkey62@163.com admin@163.com 在上面的例子中,发件人是Linux当前的登录用户名,比如我当前登录的用户名为admin,那么发送的邮箱地址是admin@163.com,如果邮箱后缀域名是163.com的话。但有时我们想写上发件人的名称,还有不想采用默认的邮箱地址,这时我们可以这么做:
复制代码代码如下:mail -s “this is a title” -r “myname@zihou.me” bbmonkey62@163.com 这时发件人邮箱就变为了 myname@zihou.me,一些垃圾邮件就是采用的这种方法,隐藏自己真实的邮件地址。 如果我们想要收件人回复邮件时,回复的邮箱地址与我们的发信邮箱不同,那么我们可以自定义回复邮箱地址,如下:
复制代码代码如下:mail -s “this is a title” -r “myname@zihou.me” -R “myreply@zihou.me” bbmonkey62@163.com 那么收信人回复时,会默认发送到myreply@zihou.me,而不是默认的myname@zihou.me。 2、发送附件 有时我们需要发送附件,那么也是非常容易的,如下:
复制代码代码如下: mail -s “this is a title” -r “myname@zihou.me” -a “/home/hadoop/report/3.txt”bbmonkey62@163.com
复制代码代码如下: echo “this is content” | mail -s “this is a title” bbmonkey62@163.com
通过echo命令来输入邮件内容“this is content”,这样就简单多了! 4、查看邮件 通过mail命令也可以查看收到的邮件,这个我就简单说一下吧,毕竟这个相对不常用,命令很简单,直接输入mail,会出现收到的邮件,每个邮件都对应一个序列号,如果要查看某封邮件,直接在?后输入数字序列号即可。 在?后输入help可以查看所有的参数,如下:
复制代码代码如下: ? help mail commands type <message list> type messages next goto and type next message from <message list> give head lines of messages headers print out active message headers delete <message list> delete messages undelete <message list> undelete messages save <message list> folder append messages to folder and mark as saved copy <message list> folder append messages to folder without marking them write <message list> file append message texts to file, save attachments preserve <message list> keep incoming messages in mailbox even if saved Reply <message list> reply to message senders reply <message list> reply to message senders and all recipients mail addresses mail to specific recipients file folder change to another folder quit quit and apply changes to folder xit quit and discard changes made to folder ! shell escape cd <directory> chdir to directory or home if none given list list names of all available commands</p><p>A <message list> consists of integers, ranges of same, or other criteria separated by spaces. If omitted, mail uses the last message typed.
在?后也可以直接输入mail写信哦,就跟上面的例子一样,所不同的是,每步都会有提示,如下:
复制代码代码如下: ? mail To: bbmonkey62@163.com Subject: this is a title content EOT