Linux如何向qq发送邮件并携带附件

1.开启qq邮箱的SMTP,并获取授权码,如下所示:

1.进入qq邮箱的设置
在这里插入图片描述
2.进入账户在这里插入图片描述
3.开启SMTP服务,并且获取到授权码
在这里插入图片描述

2.关闭Linux机器的sendmail服务,开启postfix服务

	[root@hadoop001 ~]# service sendmail stop
	[root@hadoop001 ~]# service postfix start
		
	[root@hadoop001 ~]# chkconfig --list

显示如下:
在这里插入图片描述
在这里插入图片描述

3.创建证书文件

	[root@hadoop001 ~]# mkdir -p /root/.certs/
	[root@hadoop001 ~]# echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
	[root@hadoop001 ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
	[root@hadoop001 ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
	[root@hadoop001 ~]# certutil -L -d /root/.certs
	[root@hadoop001 ~]# cd /root/.certs
	[root@hadoop001 ~]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu"  -d ./ -i qq.crt

4.修改/etc/mail.rc文件

	[root@hadoop001 ~]# vi /etc/mail.rc
	添加如下内容
	set from=xxxxxxx@qq.com						#你的qq邮箱
	set smtp=smtp.qq.com
	set smtp-auth-user=xxxxxxxx					#你的qq
	#授权码
	set smtp-auth-password=xxxxxxx				#授权码
	set smtp-auth=login
	set smtp-use-starttls
	set ssl-verify=ignore
	set nss-config-dir=/root/.certs

5.测试是否成功

	[root@hadoop001 ~]# echo  "hello word" | mail -s "title"  xxxxxxx@qq.com

此时去自己的qq邮箱查看
在这里插入图片描述
成功。

6.发送邮件带附件

	[root@hadoop001 data]# vi test.log
	test1
	test2
	test3

	[root@hadoop001 data]# vi attachment.sh
	#!/bin/bash


	FROM_EMAIL="xxxxxxx@qq.com"			#你的qq
	TO_EMAIL="xxxxxxx@qq.com"			#你的qq
	
	LOG=/root/data/test.log
	
	echo -e "`date "+%Y-%m-%d %H:%M:%S"` : Please to check the test attachement." | mailx \
	-r "From: Admin <${FROM_EMAIL}>" \
	-a ${LOG} \
	-s "Critical:DSHS test log." ${TO_EMAIL}
	
	执行该脚本
	[root@hadoop001 data]# sh attachment.sh

用到的命令是 mailx -a (添加附件) mailx -r(设置发件人地址) mail -s(指定主题)
mailx更多参数:http://linux.51yip.com/search/mailx
执行完毕后去自己的qq邮箱:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值