温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2021-07-22 23:00:55 来源:亿速云 阅读:274 作者:chen 栏目:开发技术

这篇文章主要介绍“linux下如何用脚本自动发送文本mail邮件”,在日常操作中,相信很多人在linux下如何用脚本自动发送文本mail邮件问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”linux下如何用脚本自动发送文本mail邮件”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

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

到此,关于“linux下如何用脚本自动发送文本mail邮件”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI