linux下使用 mail 命令发送电子邮件的方法

 

 
操作系统 fedora 10

mail 是系统自带的一个邮件客户端程序。

 

首先需要了解 mail 命令的常用参数

Usage: mail -eiIUdEFntBDNHRV~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS

-S OPTION users


-v
Verbose mode. The details of delivery are displayed on the user's terminal.
详细模式。投递邮件的详细过程会显示在用户的终端上。

-i
Ignore tty interrupt signals. This is particularly useful when using mail on noisy phone lines.
忽略TTY的中断信号。这个对于使用嘈杂的电话线路特别有用。

-I
Forces mail to run in interactive mode even when input isn't a terminal. In particular, the `~ ' special character when sending

mail is only active in interactive mode.
强制mail运行在交互模式,即使不是在终端上输入。当发送邮件时,特殊的字符'~'只在交互模式下起作用。

-n
Inhibits reading /etc/mail.rc upon startup.
启动的时候不读取 /etc/mail.rc 脚本文件。

-N
Inhibits the initial display of message headers when reading mail or editing a mail folder.
当读取邮件或者编辑邮件的时候不显示邮件头。

-s
Specify subject on command line (only the first argument after the -s flag is used as a subject; be careful to quote subjects

containing spaces.)
在命令行上指定邮件标题。(当标题带有空格的时候,使用双引号括起来。)

-c
Send carbon copies to list of users.
-b
Send blind carbon copies to list List should be a comma-separated list of names.
-f
Read in the contents of your mbox (or the specified file) for processing; when you quit mail writes undeleted messages back to

this file.
-u
Is equivalent to:

mail -f /var/spool/mail/user

 


使用 mail 发送邮件到互联网上的用户时,需要修改 /etc/mail.rc 脚本文件,设置发件人地址、SMTP 服务器、发件人邮箱名、密码、授权方式
vim /etc/mail.rc

set from=guwenjunbaobao@126.com smtp=smtp.126.com
set smtp-auth-user=guwenjunbaobao@126.com smtp-auth-password=******
set smtp-auth=login


密码我用******代替了

命令行上发送一封标题为 testing ,内容为 /opt/haha.txt 的邮件给收件人251338052@qq.com

mail -v -s "testing" 251338052@qq.com < /opt/haha.txt

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值