Fork me on GitHub
KeKe Blog

mail命令

mail命令是命令行的电子邮件发送和接收工具。操作的界面不像elm或pine那么容易使用,但功能非常完整。
之前工作中为了简化上传APK再手动发送相关链接给运营,这个步骤。自己写了一些同步的脚本,并将生成url通过mail命令发送邮件到我的工作邮箱。当时对mail命令的理解太浅,后来参考了很多实例,最后是注册了一个新的邮箱,mail作为一个载体工具,通过我的新邮箱向工作邮箱发送生成的url。这样大大简化了我自身的工作量,减少了90%以上的人为操作错误。

1 mail命令安装

1.1 mailx安装

  • 安装mailx
1
yum install mailx -y

1.2 配置mail.rc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 配置前;
egrep -v "^#|^$" /etc/mail.rc
set hold
set append
set ask
set crt
set dot
set keep
set emptybox
set indentprefix="> "
set quote
set sendcharsets=iso-8859-1,utf-8
set showname
set showto
set newmail=nopoll
set autocollapse
ignore received in-reply-to message-id references
ignore mime-version content-transfer-encoding
fwdretain subject date from to
set bsdcompat
# 配置后,即原有的配置冻,在文件的末尾添加5个set语句;
egrep -v "^#|^$" /etc/mail.rc
set hold
set append
set ask
set crt
set dot
set keep
set emptybox
set indentprefix="> "
set quote
set sendcharsets=iso-8859-1,utf-8
set showname
set showto
set newmail=nopoll
set autocollapse
ignore received in-reply-to message-id references
ignore mime-version content-transfer-encoding
fwdretain subject date from to
set bsdcompat
set from="oyktest@163.com"
set smtp=smtp.163.com
set smtp-auth-user=oyktest@163.com
set smtp-auth-password=ke1993
set smtp-auth=login

1.3 mail命令测试

1
2
# 配置如果没问题,一般几秒钟内就能收到邮件;
echo "ke-center" | mail -s "ke-center test" AllenKe@efun.com

2 mail常用格式

2.1 发送格式

  • 管道
1
cat /etc/passwd | mail -s "发件人名称 邮件标题" xxx@163.com,xxx@qq.com
  • 重定向输入
1
mail -s "发件人名称 邮件标题" xxx@163.com,xxx@qq.com < /etc/passwd
  • 直接编辑
1
2
# 输入完成后回车按Ctrl+D提交发送
mail -s "发件人名称 邮件标题" xxx@163.com,xxx@qq.com
-------------本文结束 感谢您的阅读-------------