下如何用脚本自动发送文本coremail邮件件

在linux中,如何写一个shell脚本程序,里面有自动发邮件的功能?
[问题点数:40分]
本版专家分:0
CSDN今日推荐
本版专家分:113137
2010年 总版技术专家分年内排行榜第六
2011年5月 Linux/Unix社区大版内专家分月排行榜第一2011年4月 Linux/Unix社区大版内专家分月排行榜第一2011年3月 Linux/Unix社区大版内专家分月排行榜第一2010年12月 Linux/Unix社区大版内专家分月排行榜第一2010年11月 Linux/Unix社区大版内专家分月排行榜第一2010年10月 Linux/Unix社区大版内专家分月排行榜第一2010年9月 Linux/Unix社区大版内专家分月排行榜第一2010年8月 Linux/Unix社区大版内专家分月排行榜第一2010年7月 Linux/Unix社区大版内专家分月排行榜第一2010年6月 Linux/Unix社区大版内专家分月排行榜第一2010年5月 Linux/Unix社区大版内专家分月排行榜第一2010年4月 Linux/Unix社区大版内专家分月排行榜第一2010年3月 Linux/Unix社区大版内专家分月排行榜第一2010年2月 Linux/Unix社区大版内专家分月排行榜第一2010年1月 Linux/Unix社区大版内专家分月排行榜第一2009年10月 Linux/Unix社区大版内专家分月排行榜第一2009年9月 Linux/Unix社区大版内专家分月排行榜第一
2011年7月 Linux/Unix社区大版内专家分月排行榜第二2011年6月 Linux/Unix社区大版内专家分月排行榜第二2011年2月 Linux/Unix社区大版内专家分月排行榜第二
2011年1月 Linux/Unix社区大版内专家分月排行榜第三2009年11月 Linux/Unix社区大版内专家分月排行榜第三
本版专家分:0
本版专家分:116
本版专家分:113137
2010年 总版技术专家分年内排行榜第六
2011年5月 Linux/Unix社区大版内专家分月排行榜第一2011年4月 Linux/Unix社区大版内专家分月排行榜第一2011年3月 Linux/Unix社区大版内专家分月排行榜第一2010年12月 Linux/Unix社区大版内专家分月排行榜第一2010年11月 Linux/Unix社区大版内专家分月排行榜第一2010年10月 Linux/Unix社区大版内专家分月排行榜第一2010年9月 Linux/Unix社区大版内专家分月排行榜第一2010年8月 Linux/Unix社区大版内专家分月排行榜第一2010年7月 Linux/Unix社区大版内专家分月排行榜第一2010年6月 Linux/Unix社区大版内专家分月排行榜第一2010年5月 Linux/Unix社区大版内专家分月排行榜第一2010年4月 Linux/Unix社区大版内专家分月排行榜第一2010年3月 Linux/Unix社区大版内专家分月排行榜第一2010年2月 Linux/Unix社区大版内专家分月排行榜第一2010年1月 Linux/Unix社区大版内专家分月排行榜第一2009年10月 Linux/Unix社区大版内专家分月排行榜第一2009年9月 Linux/Unix社区大版内专家分月排行榜第一
2011年7月 Linux/Unix社区大版内专家分月排行榜第二2011年6月 Linux/Unix社区大版内专家分月排行榜第二2011年2月 Linux/Unix社区大版内专家分月排行榜第二
2011年1月 Linux/Unix社区大版内专家分月排行榜第三2009年11月 Linux/Unix社区大版内专家分月排行榜第三
本版专家分:52
匿名用户不能发表回复!
其他相关推荐扫一扫体验手机阅读
shell 脚本自动配置发送qq邮件
<span type="1" blog_id="1880022" userid='
67篇文章,6W+人气,0粉丝
网络工程师2.0进阶指南
¥51.00286人订阅
新西兰资深网工运维之道
¥51.00568人订阅
企业级网安运维
¥51.0077人订阅
容器私有云平台实践之路
¥51.00148人订阅
运维开发全攻略
¥51.0048人订阅
高并发架构之路
¥51.00189人订阅
前百度高级工程师的架构高可用实战
¥51.00253人订阅
掌握VMware超融合技术
¥51.00102人订阅请问如何建立vbs脚本指定每次开机后自动运行,向指定邮箱发一封固定格式的邮件? - 新手入门及其它(硬件) -
恩山无线论坛 -
Powered by Discuz!
后使用快捷导航没有帐号?
只需一步,快速开始
请完成以下验证码
请完成以下验证码
查看: 5451|回复: 6
请问如何建立vbs脚本指定每次开机后自动运行,向指定邮箱发一封固定格式的邮件?
的原文如下:“ 如果要确认是否成功唤醒,可以写个简单的vbs脚本,指定每次开机后自动运行,向指定邮箱发一封固定格式的邮件,当然这里有兴趣也可以提取用户名、IP等一些信息作为邮件主题或正文。那怎么知道是否有新邮件提醒呢,邮件短信、彩信通知,很多邮件服务商都提供,移动的139邮箱就有免费通知,还支持wappush、PushMail提醒,很不错,这样你可以即刻知道是否成功唤醒电脑。”
利用tomato远程监控并自动报警、拍照并短信通知(图解)
问题:请问如何制作vbs脚本。已经脚本中的内容是怎么样的!已经vbs脚本工作流程是怎么样的!
我的恩山、我的无线
The best wifi forum is right here.
指的是Windows下面的开机脚本,搜搜便知。
我的恩山、我的无线
The best wifi forum is right here.
说的对我难度太大!有教程就好了.或者一步一步学习.
现在连怎么个流程都不知道
我的恩山、我的无线
The best wifi forum is right here.
我也有性趣啊
我的恩山、我的无线
The best wifi forum is right here.
本帖最后由 windbells888 于
18:31 编辑
不好意思,希望LZ还能回来看到,将下面文本里需要替换的内容换成你自己的,复制到记事本,保存为.vbs放到启动菜单里就可以了。
sina这个邮箱是用来发送邮件的,你可以换成其他的。139邮箱是用来接收提醒邮件并免费发送wap-push提醒到手机的
strIPPattern = &((2[0-4]\d|25[0-5]|1?\d\d?)\.){3}(2[0-4]\d|25[0-5]|1?\d\d?)&
Set objNet = createobject(&Wscript.Network&)
Set objRegExp = New RegExp
objregexp.Pattern = strIPPattern
Set objWMIService = GetObject(&winmgmts:\\.\root\cimv2&)
Set IPConfigSet = objWMIService.ExecQuery _
& & (&Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE&)
For Each IPConfig in IPConfigSet
& & If Not IsNull(IPConfig.IPAddress) Then
& && &&&For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
& && && && && && && && &If InStr(IPConfig.Caption(i),&VMware&) = 0 And InStr(IPConfig.Caption(i),&Microsoft&) = 0 Then
& && && && && && && && &If InStr(IPConfig.Caption(i),&169.254&) = 0 And InStr(IPConfig.Caption(i),&0.0.0.0&) = 0 Then
& && && && && && && && && && &&&If objregexp.Test(IPConfig.IPAddress(i)) = True Then& && &&&
& && && && && && && && && && && && &strIP = IPConfig.IPAddress(i)
& && && && && && && && && & End If
& && && && && && &&&End If
& && && && &End If
& && &&&Next
& & End If
strUser = objnet.UserName
On Error Resume Next
f=&用户名@sina.com&
smtp=&smtp.sina.com&
u=&用户名&
t=&目标邮件地址&
m=&通知内容文本&
msg= &用户名:& & strUser & vbCrLf & &IP地址:& & strIP
'j=&C:\test.rar&
NameSpace = &http://schemas.microsoft.com/cdo/configuration/&
Set Email = createObject(&CDO.Message&)
Email.From = f
Email.To = t
Email.Subject = m
Email.Textbody = msg
'Email.AddAttachment j
WScript.Sleep 1000
With Email.Configuration.Fields
.Item(NameSpace&&sendusing&) = 2
.Item(NameSpace&&smtpserver&) = smtp
.Item(NameSpace&&smtpserverport&) = 25
.Item(NameSpace&&smtpauthenticate&) = 1
.Item(NameSpace&&sendusername&) = u
.Item(NameSpace&&sendpassword&) = p
Email.Send
'MsgBox & 开机信息已通知电脑主人 &
我的恩山、我的无线
The best wifi forum is right here.
不过我用的是&&blat&&发送邮件
包括外部路由的公网IP&&其实
你可以使用如果你建立的ftp 将结果上传到ftp就可以了&&
电脑上做个连接&&一键就可以登陆ftp 看一下就知道情况了。
如果你路由有www服务那就更简单了。
我的恩山、我的无线
The best wifi forum is right here.
windbells888 你的代吧如果加上ssl支持就好了
现在smtp基本都需要ssl加密了
我的恩山、我的无线
The best wifi forum is right here.
Powered by4个可以发送完整电子邮件的命令行工具
今天的文章里我们会讲到一些使用Linux命令行工具来发送带附件的电子邮件的方法。它有很多用处,比如在应用程序所在服务器上,使用电子邮件发送一个文件过来,或者你可以在脚本中使用这些命令来做一些自动化操作。在本文的例子中,我们会使用foo.tar.gz文件作为附件。
有不同的命令行工具可以发送邮件,这里我分享几个多数用户会使用的工具,如mailx、mutt和swaks。
我们即将呈现的这些工具都是非常有名的,并且存在于多数Linux发行版默认的软件仓库中,你可以使用如下命令安装:
在 Debian / Ubuntu 系统
apt-get install mutt
apt-get install swaks
apt-get install mailx
apt-get install sharutils
在基于Red Hat的系统,如 CentOS 或者 Fedora
yum install mutt
yum install swaks
yum install mailx
yum install sharutils
1) 使用 mail / mailx
mailx工具在多数Linux发行版中是默认的邮件程序,现在已经支持发送附件了。如果它不在你的系统中,你可以使用上边的命令安装。有一点需要注意,老版本的mailx可能不支持发送附件,运行如下命令查看是否支持。
$ man mail
第一行看起来是这样的:
mailx [-BDdEFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr] [-r from-addr] [-h hops] [-A account] [-S variable[=value]] to-addr . . .
如果你看到它支持-a的选项(-a 文件名,将文件作为附件添加到邮件)和-s选项(-s 主题,指定邮件的主题),那就是支持的。可以使用如下的几个例子发送邮件。
a) 简单的邮件
运行mail命令,然后mailx会等待你输入邮件内容。你可以按回车来换行。当输入完成后,按Ctrl + D,mailx会显示EOT表示结束。
然后mailx会自动将邮件发送给收件人。
Good Morning
How are you
b) 发送有主题的邮件
$ echo "Email text" | mail -s "Test Subject"
-s的用处是指定邮件的主题。
c) 从文件中读取邮件内容并发送
$ mail -s "message send from file"
& /path/to/file
d) 将从管道获取到的echo命令输出作为邮件内容发送
$ echo "This is message body" | mail -s "This is Subject"
e) 发送带附件的邮件
$ echo &Body with attachment "| mail -a foo.tar.gz -s "attached file"
-a选项用于指定附件。
Mutt是类Unix系统上的一个文本界面邮件客户端。它有20多年的历史,在Linux历史中也是一个很重要的部分,它是最早支持进程打分和多线程处理的客户端程序之一。按照如下的例子来发送邮件。
a) 带有主题,从文件中读取邮件的正文,并发送
$ mutt -s "Testing from mutt"
& /tmp/message.txt
b) 通过管道获取echo命令输出作为邮件内容发送
$ echo "This is the body" | mutt -s "Testing mutt"
c) 发送带附件的邮件
$ echo "This is the body" | mutt -s "Testing mutt"
-a /tmp/foo.tar.gz
d) 发送带有多个附件的邮件
$ echo "This is the body" | mutt -s "Testing"
-a foo.tar.gz &a bar.tar.gz
Swaks(Swiss Army Knife,瑞士军刀)是SMTP服务上的瑞士军刀,它是一个功能强大、灵活、可编程、面向事务的SMTP测试工具,由John Jetmore开发和维护。你可以使用如下语法发送带附件的邮件:
$ swaks -t "" --header "Subject: Subject" --body "Email Text" --attach foo.tar.gz
关于Swaks一个重要的地方是,它会为你显示整个邮件发送过程,所以如果你想调试邮件发送过程,它是一个非常有用的工具。
它会给你提供了邮件发送过程的所有细节,包括邮件接收服务器的功能支持、两个服务器之间的每一步交互。
(LCTT 译注:原文此处少了&sharutils 的相关介绍,而多了 uuencode 的介绍。)
4) uuencode
邮件传输系统最初是被设计来传送7位编码(类似ASCII)的内容的。这就意味这它是用来发送文本内容,而不能发会使用8位的二进制内容(如程序文件或者图片)。uuencode(&UNIX to UNIX encoding&,UNIX之间使用的编码方式)程序用来解决这个限制。使用uuencode,发送端将二进制格式的转换成文本格式来传输,接收端再转换回去。
我们可以简单地使用uuencode和mailx或者mutt配合,来发送二进制内容,类似这样:
$ uuencode example.jpeg example.jpeg | mail
Shell脚本:解释如何发送邮件
#!/bin/bash
SUBJECT=""
ATTACHMENTS=""
# 检查文件名对应的文件是否存在
function check_files()
output_files=""
for file in $1
if [ -s $file ]
output_files="${output_files}${file} "
echo $output_files
echo "*********************"
echo "E-mail sending script."
echo "*********************"
# 读取用户输入的邮件地址
while [ 1 ]
if [ ! $FROM ]
echo -n -e "Enter the e-mail address you wish to send mail from:\n[Enter] "
echo -n -e "The address you provided is not valid:\n[Enter] "
echo $FROM | grep -E '^.+@.+$' & /dev/null
if [ $? -eq 0 ]
# 读取用户输入的收件人地址
while [ 1 ]
if [ ! $TO ]
echo -n -e "Enter the e-mail address you wish to send mail to:\n[Enter] "
echo -n -e "The address you provided is not valid:\n[Enter] "
echo $TO | grep -E '^.+@.+$' & /dev/null
if [ $? -eq 0 ]
# 读取用户输入的邮件主题
echo -n -e "Enter e-mail subject:\n[Enter] "
read SUBJECT
if [ "$SUBJECT" == "" ]
echo "Proceeding without the subject..."
# 读取作为附件的文件名
echo -e "Provide the list of attachments. Separate names by space.
If there are spaces in file name, quote file name with \"."
# 确保文件名指向真实文件
attachments=$(check_files "$att")
echo "Attachments: $attachments"
for attachment in $attachments
ATTACHMENTS="$ATTACHMENTS-a $attachment "
# 读取完整的邮件正文
echo "Enter message. To mark the ; in new line."
while [ "$line" != ";;" ]
BODY="$BODY$line\n"
SENDMAILCMD="mutt -e \"set from=$FROM\" -s \"$SUBJECT\" \
$ATTACHMENTS -- \"$TO\" &&& \"$BODY\""
echo $SENDMAILCMD
mutt -e "set from=$FROM" -s "$SUBJECT" $ATTACHMENTS -- $TO &&& $BODY
** 脚本输出 **
$ bash send_mail.sh
*********************
E-mail sending script.
*********************
Enter the e-mail address you wish to send mail from:
Enter the e-mail address you wish to send mail to:
Enter e-mail subject:
[Enter] Message subject
Provide the list of attachments. Separate names by space.
If there are spaces in file name, quote file name with ".
send_mail.sh
Attachments: send_mail.sh
Enter message. To mark the ; in new line.
This is a message
有很多方法可以使用命令行/Shell脚本来发送邮件,这里我们只分享了其中4个类Unix系统可用的工具。希望你喜欢我们的文章,并且提供您的宝贵意见,让我们知道您想了解哪些新工具。
作者: 译者: 校对:
原创翻译, 荣誉推出
共计翻译: 10.0 篇
| 共计贡献: 29 天
贡献时间: -&
-12%-35%-47%-56%-63%-91%
今天的文章里我们会讲到一些使用Linux命令行工具来发送带附件的电子邮件的方法。它有很多用处,比如在应用程序所在服务器上,使用电子邮件发送一个文件过来,或者你可以在脚本中使用这些命令来做一些自动化操作。在本文的例子中,我们会使用foo.tar.gz文件作为附件。 有不同的命令行工具可以发送邮件,这里我分享几个多数用户会使用的工具,如mailx、mutt和swaks。 我们即将呈现的这些工具都是非常有名的,并且存在于多数Linux发行版默认的软件仓库中,你可以使用如下命令安装: 在 Debian / Ubuntu 系统 apt-get install mutt apt-get in
上一篇:下一篇:
评论功能关闭
根据国家法律法规要求,本站暂时关闭文章评论功能。开放时间不确定。我们将谋求一种可以让大家更好的发表意见的方式。
根据国家法律法规要求,只有实名认证后才可以发表评论。
12:08 的评论:
然而我163邮箱并没有收到邮件
收到了,但是好慢,我早上发的,午睡后才收到
那不是你发送方式的原因,是你的邮件服务器的原因。
我认为是163邮箱服务器的原因
分享到微信
打开微信,点击顶部的“╋”,
使用“扫一扫”将网页分享至微信。
请将我们加入您的广告过滤器的白名单,请支持开源站点。谢谢您。1、安装和配置sendmail
不需要注册公网域名和MX记录(不需要架设公网邮件服务器),通过Linux系统自带的mail命令即可对公网邮箱发送邮件。不过mail命令是依赖sendmail的,所以我们需要先检查安装和配置sendmail。
一般系统都自带sendmail,但是只能给内网的邮箱发邮件。如果想给公网的邮箱发邮件(比如qq邮箱)就需要配置sendmail.
这里记录sendmail的安装启动配置,各取所需。
尝试使用mail命令发送一封邮件。
root@ubuntu4146:/data/gitlabData/backups.com
The program 'mail' is currently not installed. You can install it by typing:
apt-get install mailutils
发送失败,命令mail没有安装
因此,我们使用 apt-get install mailutils 命令安装mailutils
root@ubuntu4146:/data/gitlabData/backups
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
下列软件包是自动安装的并且现在不需要了:
lib32asan0 lib32atomic1 lib32gcc-4.8-dev lib32gcc1 lib32gomp1 lib32itm1
lib32quadmath0 lib32stdc++-4.8-dev lib32stdc++6 libbonobo2-common
libc6-dev-x32 libc6-x32 libgnome2-common libltdl-dev liborbit-2-0 libssl-dev
libssl-doc libstdc++-4.8-dev libx32asan0 libx32atomic1 libx32gcc-4.8-dev
libx32gcc1 libx32gomp1 libx32itm1 libx32quadmath0 libx32stdc++-4.8-dev
libx32stdc++6 pkg-php-tools shtool
Use 'apt-get autoremove' to remove them.
将会安装下列额外的软件包:
guile-2.0-libs libgsasl7 libkyotocabinet16 liblzo2-2 libmailutils4 libntlm0
mailutils-common
建议安装的软件包:
mailutils-mh mailutils-doc
下列【新】软件包将被安装:
guile-2.0-libs libgsasl7 libkyotocabinet16 liblzo2-2 libmailutils4 libntlm0
mailutils mailutils-common
升级了 0 个软件包,新安装了 8 个软件包,要卸载 0 个软件包,有 310 个软件包未被升级。
需要下载 3,461 kB 的软件包。
解压缩后会消耗掉 18.0 MB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://cn.archive.ubuntu.com/ubuntu/ trusty-updates/main liblzo2-2 amd64 2.06-1.2ubuntu1.1 [46.1 kB]
获取:2 http://cn.archive.ubuntu.com/ubuntu/ trusty/universe libkyotocabinet16 amd64 1.2.76-4 [288 kB]
获取:3 http://cn.archive.ubuntu.com/ubuntu/ trusty/universe libntlm0 amd64 1.4-1 [15.3 kB]
获取:4 http://cn.archive.ubuntu.com/ubuntu/ trusty/main guile-2.0-libs amd64 2.0.9+1-1ubuntu1 [2,127 kB]
获取:5 http://cn.archive.ubuntu.com/ubuntu/ trusty/universe libgsasl7 amd64 1.8.0-2ubuntu2 [117 kB]
获取:6 http://cn.archive.ubuntu.com/ubuntu/ trusty/universe mailutils-common all 1:2.99.98-1.1 [245 kB]
获取:7 http://cn.archive.ubuntu.com/ubuntu/ trusty/universe libmailutils4 amd64 1:2.99.98-1.1 [398 kB]
获取:8 http://cn.archive.ubuntu.com/ubuntu/ trusty/universe mailutils amd64 1:2.99.98-1.1 [225 kB]
下载 3,461 kB,耗时 2秒 (1,283 kB/s)
Selecting previously unselected package liblzo2-2:amd64.
(正在读取数据库 ... 系统当前共安装有 172915 个文件和目录。)
Preparing to unpack .../liblzo2-2_2.06-1.2ubuntu1.1_amd64.deb ...
Unpacking liblzo2-2:amd64 (2.06-1.2ubuntu1.1) ...
Selecting previously unselected package libkyotocabinet16:amd64.
Preparing to unpack .../libkyotocabinet16_1.2.76-4_amd64.deb ...
Unpacking libkyotocabinet16:amd64 (1.2.76-4) ...
Selecting previously unselected package libntlm0:amd64.
Preparing to unpack .../libntlm0_1.4-1_amd64.deb ...
Unpacking libntlm0:amd64 (1.4-1) ...
Selecting previously unselected package guile-2.0-libs.
Preparing to unpack .../guile-2.0-libs_2.0.9+1-1ubuntu1_amd64.deb ...
Unpacking guile-2.0-libs (2.0.9+1-1ubuntu1) ...
Selecting previously unselected package libgsasl7.
Preparing to unpack .../libgsasl7_1.8.0-2ubuntu2_amd64.deb ...
Unpacking libgsasl7 (1.8.0-2ubuntu2) ...
Selecting previously unselected package mailutils-common.
Preparing to unpack .../mailutils-common_1%3a2.99.98-1.1_all.deb ...
Unpacking mailutils-common (1:2.99.98-1.1) ...
Selecting previously unselected package libmailutils4.
Preparing to unpack .../libmailutils4_1%3a2.99.98-1.1_amd64.deb ...
Unpacking libmailutils4 (1:2.99.98-1.1) ...
Selecting previously unselected package mailutils.
Preparing to unpack .../mailutils_1%3a2.99.98-1.1_amd64.deb ...
Unpacking mailutils (1:2.99.98-1.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
正在设置 liblzo2-2:amd64 (2.06-1.2ubuntu1.1) ...
正在设置 libkyotocabinet16:amd64 (1.2.76-4) ...
正在设置 libntlm0:amd64 (1.4-1) ...
正在设置 guile-2.0-libs (2.0.9+1-1ubuntu1) ...
正在设置 libgsasl7 (1.8.0-2ubuntu2) ...
正在设置 mailutils-common (1:2.99.98-1.1) ...
正在设置 libmailutils4 (1:2.99.98-1.1) ...
正在设置 mailutils (1:2.99.98-1.1) ...
update-alternatives: using /usr/bin/frm.mailutils to provide /usr/bin/frm (frm) in 自动模式
update-alternatives: using /usr/bin/from.mailutils to provide /usr/bin/from (from) in 自动模式
update-alternatives: using /usr/bin/messages.mailutils to provide /usr/bin/messages (messages) in 自动模式
update-alternatives: using /usr/bin/movemail.mailutils to provide /usr/bin/movemail (movemail) in 自动模式
update-alternatives: using /usr/bin/readmsg.mailutils to provide /usr/bin/readmsg (readmsg) in 自动模式
update-alternatives: using /usr/bin/dotlock.mailutils to provide /usr/bin/dotlock (dotlock) in 自动模式
update-alternatives: using /usr/bin/mail.mailutils to provide /usr/bin/mailx (mailx) in 自动模式
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
root@ubuntu4146:/data/gitlabData/backups
2、使用shell脚本发送Email
首先执行命令mail --help 查找mail命令的用法
root@ubuntu4146:/data/gitlabData/backups# mail --help
Usage: mail [OPTION...] [address...]
mail [OPTION...] -f [OPTION...] [file]
mail [OPTION...] --file [OPTION...] [file]
mail [OPTION...] --file=file [OPTION...]
GNU mail -- process mail messages.
If -f or --file is given, mail operates on the mailbox named by the first
argument, or the user's mbox, if no argument given.
-a, --append=HEADER: VALUE append given header to the message being sent
-A, --attach=FILE
attach FILE
--content-type=TYPE
set content type for subsequent --attach options
-e, --exist
return true if mail exists
--encoding=NAME
set encoding for subsequent --attach options
-E, --exec=COMMAND
execute COMMAND
-F, --byname
save messages according to sender
-H, --headers
write a header summary and exit
-i, --ignore
ignore interrupts
-n, --norc
do not read the system mailrc file
-N, --nosum
do not display initial header summary
-p, --print, --read
print all mail to standard output
-q, --quit
cause interrupts to terminate program
-r, --return-address=ADDRESS
use address as the return address when sending
-s, --subject=SUBJ
send a message with the given SUBJECT
precede message by a list of addresses
-u, --user=USER
operate on USER's mailbox
Common options
--config-file=FILE, --rcfile=FILE
load this configuration file
--config-help
show configuration file summary
--config-lint, --rcfile-lint
check configuration file syntax and exit
--config-verbose, --rcfile-verbose
verbosely log parsing of the configuration files
--no-site-config, --no-site-rcfile
do not load site configuration file
--no-user-config, --no-user-rcfile
do not load user configuration file
--set=PARAM=VALUE
set configuration parameter
--show-config-options
show compilation options
Global debugging settings
--debug-level=LEVEL
set Mailutils debugging level
--debug-line-info
show source info with debugging messages
-?, --help
give this help list
give a short usage message
-V, --version
print program version
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Report bugs to &bug-mailutils@gnu.org&.
root@ubuntu4146:/data/gitlabData/backups#
2.1 无邮件正文
mail -s "主题"
例如我们执行:
root@ubuntu4146:/data/gitlabData/backups.dw.gdbbk.com
Null hope that's ok
root@ubuntu4146:/data/gitlabData/backups#
提示你输入Cc地址,即邮件抄送地址,没有抄送地址则直接回车就完成了邮件的发送。
接着会让你输入邮件正文,当邮件正文输入完成后,需要按CTRL+D结束输入。此时我们不填写邮件正文,直接按CTRL+D结束输入。它会提示我们N hope that’s ok。
此时查看OA邮件,可以收到刚才发送过来的无正文的邮件。
2.2 有邮件正文
2.2.1 echo “邮件正文” | mail -s 邮件主题
执行管道命令,来填写邮件正文,例如我们执行命令:
root@ubuntu4146:/.dw.gdbbk.com
root@ubuntu4146:/
这时,我们收到的OA邮件内容如下:
mail -s “主题”
收件地址& 文件(邮件正文)
例如我们执行如下命令,则将/data/gitlabData/backups/log/.log 文件内容当做邮件正文发送了。
root@ubuntu4146:/# mail -s "Email Subject : Hello from Linux Server by shell" ouyangpeng@oaserver.dw.gdbbk.com & /data/gitlabData/backups/log/2017-08-18.log
这时,我们收到的OA邮件内容如下:
2.2.3 cat 邮件正文.txt | mail -s 邮件主题
例如我们执行如下命令,则将/data/gitlabData/backups/log/.log 文件内容当做邮件正文发送了。
root@ubuntu4146:/# cat /data/gitlabData/backups/log/2017-08-17.log | mail -s "Email Subject : Hello from Linux Server by shell" ouyangpeng@oaserver.dw.gdbbk.com
这时,我们收到的OA邮件内容如下:
2.3 邮件附件
mail -s “主题”
root@ubuntu4146:/.dw.gdbbk.com -A /data/gitlabData/backups/log/.log
This email attach a file.
root@ubuntu4146:/
提示你输入Cc地址,即邮件抄送地址,没有抄送地址则直接回车就完成了邮件的发送。
接着会让你输入邮件正文 “This email attach a file.”,当邮件正文输入完成后,需要按CTRL+D结束输入。
这时,我们收到的OA邮件内容如下:
2.3.2 mail -s “主题”
-a 附件 & 文件(邮件正文.txt)
root@ubuntu4146:/# mail -s "Email Subject : Hello from Linux Server by shell" ouyangpeng@oaserver.dw.gdbbk.com -A /data/gitlabData/backups/auto_backup.sh & /data/gitlabData/backups/log/2017-08-18.log
执行如上命令,/data/gitlabData/backups/auto_backup.sh 会当做附件发送,/data/gitlabData/backups/log/.log 的内容会当做正文发送
这时,我们收到的OA邮件内容如下:
3、发送给多个人
root@ubuntu4146:/data/gitlabData/backups# mail --help
Usage: mail [OPTION...] [address...]
mail [OPTION...] -f [OPTION...] [file]
mail [OPTION...] --file [OPTION...] [file]
mail [OPTION...] --file=file [OPTION...]
GNU mail -- process mail messages.
If -f or --file is given, mail operates on the mailbox named by the first
argument, or the user's mbox, if no argument given.
-a, --append=HEADER: VALUE append given header to the message being sent
-A, --attach=FILE
attach FILE
--content-type=TYPE
set content type for subsequent --attach options
-e, --exist
return true if mail exists
--encoding=NAME
set encoding for subsequent --attach options
-E, --exec=COMMAND
execute COMMAND
-F, --byname
save messages according to sender
-H, --headers
write a header summary and exit
-i, --ignore
ignore interrupts
-n, --norc
do not read the system mailrc file
-N, --nosum
do not display initial header summary
-p, --print, --read
print all mail to standard output
-q, --quit
cause interrupts to terminate program
-r, --return-address=ADDRESS
use address as the return address when sending
-s, --subject=SUBJ
send a message with the given SUBJECT
precede message by a list of addresses
-u, --user=USER
operate on USER's mailbox
Common options
--config-file=FILE, --rcfile=FILE
load this configuration file
--config-help
show configuration file summary
--config-lint, --rcfile-lint
check configuration file syntax and exit
--config-verbose, --rcfile-verbose
verbosely log parsing of the configuration files
--no-site-config, --no-site-rcfile
do not load site configuration file
--no-user-config, --no-user-rcfile
do not load user configuration file
--set=PARAM=VALUE
set configuration parameter
--show-config-options
show compilation options
Global debugging settings
--debug-level=LEVEL
set Mailutils debugging level
--debug-line-info
show source info with debugging messages
-?, --help
give this help list
give a short usage message
-V, --version
print program version
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Report bugs to &bug-mailutils@gnu.org&.
root@ubuntu4146:/data/gitlabData/backups#
查看上面的mail帮助文档,使用 -t 选项 指定一个收件人列表。
下面测试发送一封邮件给3个人,如下所示:
root@ubuntu4146:/data/gitlabData/backups.dw.gdbbk.com ouyangpeng.dw.gdbbk.com huxiaoqiao.dw.gdbbk.com
OA邮箱收到邮件可以看到有三个收件人。
上面的命令是Ubuntu系统的mail命令的用法,但是在Center OS系统时,该命令有所不同
首先通过如下命令lsb_release -a 查看系统版本
[root@localhost gitlabDataBackup]#
:base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
然后使用命令 man help 查看mail命令的用法
[root@localhost gitlabDataBackup]# mail
mail: illegal option
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
[root@localhost gitlabDataBackup]#
使用 man mail 命令查看mail的更加具体的用法
User Commands
mailx - send and receive Internet mail
mailx [-BDdEFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr] [-r from-addr] [-h hops] [-A account] [-S variable[=value]] to-addr . . .
mailx [-BDdeEHiInNRv~] [-T name] [-A account] [-S variable[=value]] -f [name]
mailx [-BDdeEinNRv~] [-A account] [-S variable[=value]] [-u user]
DESCRIPTION
Mailx is an intelligent mail processing system, which has a command syntax reminiscent of ed(1) with lines replaced by messages.
It is based on Berkeley Mail 8.1,
is intended to provide the functionality of the POSIX mailx command, and offers extensions for MIME, IMAP, POP3, SMTP, and S/MIME.
for interactive use, such as caching and disconnected operation for IMAP, message threading, scoring, and filtering.
It is also usable as a mail batch lan-
guage, both for sending and receiving mail.
The following options are accepted:
Executes an account command (see below) for name after the startup files have been read.
Attach the given file to the message.
Make standard input and standard output line-buffered.
-b address
Send blind carbon copies to list.
List should be a comma-separated list of names.
-c address
Send carbon copies to list of users.
Start in see the description for the disconnected variable option.
Enables debugging messages and disables the actual delivery of messages.
Unlike -v, this option is intended for mailx development only.
Just check if mail is present in the system mailbox.
If yes, return an exit status of zero, else, a non-zero value.
If an outgoing message does not contain any text in its first or only message part, do not send it but discard it silently, effectively setting the skipemp-
tybody variable at program startup.
This is useful for sending messages from scripts started by cron(8).
of the user’s mbox (or the specified file) for when mailx is quit, it writes undeleted messages back to this file.
string file is handled as described for the folder command below.
Save the message to send in a file named after the local part of the first recipient’s address.
Print header summaries for all messages and exit.
Invoke sendmail with the specified hop count.
This option has no effect when SMTP is used for sending mail.
Ignore tty interrupt signals.
This is particularly useful when using mailx on noisy phone lines.
Shows the ‘Newsgroup:’ or ‘Article-Id:’ fields in the header summary.
Only applicable in combination with -f.
Inhibits reading /etc/mail.rc upon startup.
This option should be activated for mailx scripts that are invoked on more than one machine, because
tents of that file may differ between them.
Inhibits the initial display of message headers when reading mail or editing a mail folder.
Start the message with the contents of the specified file.
May be given in send mode only.
-r address
from variable specified in environment or startup files.
Tilde escapes are disabled.
The -r address options are
passed to the mail transfer agent unless SMTP is used.
This option exists for it is recommended
Opens any folders read-only.
-s subject
Specify subject on command line (only the first argument after the -s flag is used as be careful to quote subjects containing spaces).
-S variable[=value]
Sets the internal option variable and, in case of a string option, assigns value to it.
the ‘Message-Id:’ and ‘Article-Id:’ header fields of each message read in the file name.
Implies -I.
Compressed files are handled as described for
the folder command below.
The message to be sent is expected to contain a message header with ‘To:’, ‘Cc:’, or ‘Bcc:’ fields giving its recipients.
Recipients specified on the
mand line are ignored.
Reads the mailbox of the given user name.
Verbose mode.
The details of delivery are displayed on the user’s terminal.
Print mailx’s version and exit.
Enable tilde escapes even if not in interactive mode.
后面还有很多介绍,就不贴代码了
由上面可以发现,Ubuntu的mail命令和Center OS系统的mail命令是不一样的,因此在Center OS 系统想同时发生给多个人的话,不能使用-t选项。
因此在Center OS 上,使用如下命令来进行给多个人发送邮件
[root@localhost gitlabDataBackup]# echo "Test send mail to multiple people" | mail -s "Congratulation! GitLab clean old backupFiles Success Report." -a /root/gitlabDataBackup/log/2017-08-21.log ouyangpeng@oaserver.dw.gdbbk.com -c yizhongwei@oaserver.dw.gdbbk.com,huxiaoqiao@oaserver.dw.gdbbk.com
You have new mail in /var/spool/mail/root
[root@localhost gitlabDataBackup]#
收到的OA邮件如下所示:
4、检查邮件是否发出
检查所传送的电子邮件是否送出,或滞留在邮件服务器中
/usr/lib/sendmail -bp
若屏幕显示为“Mail queue is empty” 的信息,表示mail 已送出。
若为其他错误信息,表示电子邮件因故尚未送出。
例如下面执行命令之后,就可以看到有些很久之前的邮件没有发送出去。
5、读取邮件
系统收到邮件都会保存在“/var/spool/mail/[linux用户名]”文件中。
在linux中输入mail回车 ,就进入了收件箱,并显示邮件列表。
root@ubuntu4146:/# mail
"/var/mail/root": 3 messages 3 new
1 Cron Daemon
8月 15 10: 147/5848
Cron &root@ubuntu4146& /data/gitlabData/backups/auto_backup.sh -D 1
2 Cron Daemon
8月 15 10: 147/5848
Cron &root@ubuntu4146& /data/gitlabData/backups/auto_backup.sh -D 1
3 Cron Daemon
8月 16 06:
Cron &root@ubuntu4146& test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
Return-Path: &root@ubuntu4146.ubantu4146&
X-Original-To: root
Delivered-To: root@ubuntu4146.ubantu4146
Received: by ubuntu4146.ubantu4146 (Postfix, from userid 0)
id 5A4AC1463CE
From: root@ubuntu4146.ubantu4146 (Cron Daemon)
To: root@ubuntu4146.ubantu4146
Subject: Cron &root@ubuntu4146& /data/gitlabData/backups/auto_backup.sh -D 1
Content-Type: text/plain
X-Cron-Env: &SHELL=/bin/sh&
X-Cron-Env: &PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin&
X-Cron-Env: &HOME=/root&
X-Cron-Env: &LOGNAME=root&
Message-Id: &37.5A4AC1463CE@ubuntu4146.ubantu4146&
Date: Tue, 15 Aug 2017 10:30:37 +0800 (CST)
6、编写shell脚本监控执行任务然后邮件通知
可以参考我下一篇博客
博客里面详细说明了如何进行任务监控以及邮件通知!
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:
如果本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行打赏。
扫码向博主提问
非学,无以致疑;非问,无以广识
擅长领域:
linux邮件发送测试 直接shell/smpt发送
1、直接使用shell当编辑器和三方smtp发送方法
mail -s &Hello from mzone.cc by shell& admin@mzone.cchello,this is the co...
shell中发送邮件方法小结
mail是unix-like中发送和接收邮件的程序。linux的每一个账户都有一个信箱/var/spool/mail/wahaha(未读邮件),还有一个收件箱~/mbox(已读邮件会放到...
linux shell 发送email 邮件
方法一:简单邮件发送
echo “hello world& | mail -s &Subject& yanggang_
方法二: 文本格式发送邮件
Linux Shell发邮件笔记
Linux作为首屈一指的服务器级别的操作系统,邮件系统的使用非常简单(一行命令),虽然网上已经有很多Shell发邮件的文章帖子已经足够参考使用(例如:http://blog.csdn.net/kevi...
shell下发送邮件工具sendEmail的用法详解
今天来分享一个可以在linux命令行(shell)模式下使用的发送电子邮件的软件
首先上下载地址:http://caspian.dotconf.net/menu/Software/SendEmail/...
shell mail命令发送email
linux shell 發送email的命令
body:&This is test mail&
title/subject:'Test mail'
发件人地址
-F ...
shell下进行利用mail命令进行邮件的发送
有时候想进行一些小型数据的备份,保存到本机看
环境:ubuntu10.04
首先要安装软件包mailutils :apt-get install heirloom-mailx
1、先通过通过mail给系统内的其他用户发送邮件
没有更多推荐了,
(window.slotbydup=window.slotbydup || []).push({
id: "5865577",
container: s,
size: "300,250",
display: "inlay-fix"

我要回帖

更多关于 javamail发送秘密邮件 的文章

 

随机推荐