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 [email protected] smtp=smtp.126.com
set [email protected] smtp-auth-password=******
set smtp-auth=login


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

命令行上发送一封标题为 testing ,内容为 /opt/haha.txt 的邮件给收件人[email protected]

mail -v -s "testing" [email protected] < /opt/haha.txt

 

你可能感兴趣的:(linux下使用 mail 命令发送电子邮件的方法)