linux mail 命令 (收发邮件)


Ubuntu:
首先安装mail
sudo apt-get install mailx

再次安装postfix
sudo apt-get install postfix
(安装过程中要进行配置,按照提示即可完成)

发送邮件命令示例
cat "content"| mail -s "subject" yl33643@126.com

Debian / Ubuntu 系统

  1. apt-get install mutt
  2. apt-get install swaks
  3. apt-get install mailx
  4. apt-get install sharutils

在基于Red Hat的系统,如CentOS 或者Fedora

  1. yum install mutt
  2. yum install swaks
  3. yum install mailx
  4. yum install sharutils


echo "This is the body"| mutt -s "Subject" test@example.com.cn

sendmail的配置宏文件:/etc/mail/sendmail.mc

vi  /etc/mail/sendmail.mc

sharutils:(uuencode) 2 send attachments

1. 如何查看linux的mailqueue
$mailq
$sendmail -bp
$ll /var/spool/mqueue  这是mail队列存放的目录,可以将里面的文件删除来清空mailqueue
可以通过这些命令来查看邮件是否送出

 

2. 如何发送mail
1)将文件当做电子邮件的内容送出
语法:mail -s “主题”用户名@地址< 文件
例如:
$mail -s "send with content that is a file" sherry@geminimobile.com < install.log
2)传送mail给本系统用户
$mail 用户名
3)编辑邮件内容
$mail sherry@geminimobile
Subject: messge for job  编辑标题后回车
Apple this job. 开始编辑内容,结束后按Ctrl+D退出内容编辑
Cc:     输入cc地址,如果没有可以直接回车将邮件发送出去
注:Ctrl+C可以中断邮件编辑
4)快速发送邮件
$echo “邮件正文” | mail -s 邮件主题 sherry@geminimobile.com
5)发送附件
$uuencode 附件名 显示附件名 | mail -s "subject" sherry@geminimobile.com
注:uuencode是将二进制文件转换为文本文件的过程,转换后的文件可以通过纯文本e-mail进行传输,在接收方对该文件进行uudecode,即将其转换为初始的二进制文件。

6)发送邮件时增加-v选项可以在终端看到邮件服务器的response

[root@tc-40432-5s ~]# mail -v -s "send with content that is a file" sherry@geminimobile.com < install.log
sherry@geminimobile.com... Connecting to [127.0.0.1] via relay...
220 localhost.localdomain ESMTP Sendmail 8.13.1/8.13.1; Mon, 13 Dec 2010 14:40:13 +0800
>>> EHLO localhost.localdomain
250-localhost.localdomain Hello tc-40432-5s [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
>>> MAIL From:<root@localhost.localdomain> SIZE=60054 AUTH=root@localhost.localdomain
250 2.1.0 <root@localhost.localdomain>... Sender ok
>>> RCPT To:<sherry@geminimobile.com>
>>> DATA
250 2.1.5 <sherry@geminimobile.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 oBD6eDwW006082 Message accepted for delivery
sherry@geminimobile.com... Sent (oBD6eDwW006082 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 localhost.localdomain closing connection

 

3. 系统收到的mail会保存在/var/spool/mail/用户名 文件夹中
收mail,键入mail就会显示当前用户的前20封mail。可对邮件进行查看删除等操作。键入?可显示所有命令
$mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/root": 37 messages 37 new
>N  1 root@localhost.local  Mon Dec 13 11:55  21/940   "Cron <root@tc-40432-5s      /usr/sbin/logrotate /usr/local/gemini/hss/3.0.0-ga1/etc/logrotate-stats/hss-stats-rotate"
.
.
.
& ?
    Mail   Commands
t <message list>                type messages
                              goto and type next message
e <message list>                edit messages
f <message list>                give head lines of messages
d <message list>                delete messages
s <message list> file           append messages to file
u <message list>                undelete messages
R <message list>                reply to message senders
r <message list>                reply to message senders and all recipients
pre <message list>              make messages go back to /usr/spool/mail
m <user list>                   mail to specific users
                              quit, saving unresolved messages in mbox
                              quit, do not remove system mailbox
                              print out active message headers
                              shell escape
cd [directory]                  chdir to directory or home if none given

A <message list> consists of integers, ranges of same, or user names separated
by spaces.  If omitted, Mail uses the last message typed.

A <user list> consists of user names or aliases separated by spaces.
Aliases are defined in .mailrc in your home directory.

在linux文本命令平台输入 mail -f mbox,就可以看到当前目录下的mbox中的邮件了。
cd 改变当前所在文件夹的位置
读信时,按一次Ctrl+C,退出阅读状态。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值