建站极客
脚本专栏 linux shell 正文
浅析linux下如何用脚本自动发送文本mail邮件
所属分类:
脚本专栏 / linux shell
阅读数:
946
收藏 0
赞 0
分享
1. 安装msmtp luther@gliethttp:~$ sudo apt-get install msmtp 2. 编辑配置脚本(~/.msmtprc是默认配置文件,也可以使用-C选项指定配置文件路径) luther@gliethttp:~$ vim msmtprc #添加如下内容 defaults #logfile /home/luther/msmtp.log account luther_test host mail.gliethttp.cn from luther@gliethttp.cn auth off password 123456789 account default : luther_test 3. 去掉配置文件的执行权限-x luther@gliethttp:~$ chmod 600 msmtprc 4. 好了,可以使用下面语句发送一个测试邮件到自己的邮箱了,或者在stdin上输入,然后ctrl+D 可能文件中的部分数据会丢失,不怕,当我们安装mutt之后就一切正常了. luther@gliethttp:~$ msmtp luther@gliethttp.cn -C /home/luther/msmtprc < /vobs/tmp/log.c 5. 接着安装mutt luther@gliethttp:~$ sudo apt-get install mutt 6. 编辑配置脚本(~/.muttrc是默认配置文件,也可以使用-F选项指定配置文件路径) luther@gliethttp:~$ vim muttrc #添加如下内容 set sendmail="/usr/bin/msmtp -C /home/luther/msmtprc" set use_from=yes set from=admin@gliethttp.cn set realname="测试admin" set editor="vim" 7. 发送普通文本和文件内容 luther@gliethttp:~$ echo "测试123abc" | mutt -F /home/luther/muttrc -s "邮件标题 - 测试" luther@gliethttp.cn luther@gliethttp:~$ mutt -F /home/luther/muttrc -s "邮件标题 - 测试" luther@gliethttp.cn < /etc/passwd 8. 发送附件(-a选项用来添加附件,下面这个例子添加了passwd和resolv.conf这2个附件) luther@gliethttp:~$ echo "测试123abc" | mutt -F /home/luther/muttrc -s "邮件标题 - 测试" luther@gliethttp.cn -a /etc/passwd -a /etc/resolv.conf 9. bcc地址和cc抄送地址发送,如果多个邮件地址,使用逗号分隔即可 luther@gliethttp:~$ echo "测试123abc" | mutt -F /home/luther/muttrc -s " 邮件标题 - 测试" luther@gliethttp.cn,luther.ge@163.com -b luther.ge@163.com,luther@gliethttp.cn -c luther.ge@163.com,luther@gliethttp.cn
shell脚本编程之循环语句学习笔记 这篇文章主要介绍了shell脚本编程之循环语句学习笔记,本文内容较简单,可以作为shell循环语句的备忘录,忘记怎么写时来看看吧~需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
Shell脚本实现的阳历转农历代码分享 这篇文章主要介绍了Shell脚本实现的阳历转农历代码分享,本文是作者一个星期的工作成果,得来不易,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
Shell脚本实现批量下载网络图片代码分享 这篇文章主要介绍了Shell脚本实现批量下载网络图片代码分享,本文基于下载Yahoo天气图标而写,图片地址需有一定的规则,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
Shell脚本数组用法小结 这篇文章主要介绍了Shell脚本数组用法小结,本文讲解了数组声明、数组遍历、获取数组长度、删除数组元素、数组切片等内容,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
Shell脚本批量重命名文件后缀的3种实现 这篇文章主要介绍了Shell脚本批量重命名文件后缀的3种实现,本文分别使用find + xargs +sed、for循环、rename等3种方法实现重命名文件后缀,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
C语言实现的ls命令源码分享 这篇文章主要介绍了C语言实现的ls命令源码分享,本文是学习apue的练手之作,需要的朋友可以参考下
评论 0
收藏 0
赞 0
分享
查看更多