网站首页 > 开源技术 正文
Linux发送外网邮件设置(含ssl协议)
最近工作中遇到需要监控Linux服务器内存的使用情况。然后发送邮件通知。只是个单点需求没有使用zabbix等监控工具,简单使用脚本做下监控。期间遇到由于使用的是阿里的云主机,默认25端口关闭了,所以使用了ssl协议发送邮件。整理出来供大家参考。
一、发送普通邮件
1、开机postfix邮件服务
service postfix start
2、检查是否安装mailx
rpm -qa | grep mailx
3、编辑配置mail.rc配置文件
vi /etc/mail.rc
在文件末尾添加如下内容
set from=xxx@163.com #发件邮箱 set smtp=smtp.163.com #发送服务器 set smtp-auth-user= #账号 set smtp-auth-password= #密码 set smtp-auth=login #登录
此处需注意,如果是网易游戏,密码为客户端授权密码。
4、通过命令测试
echo hello word | mail -s " title" xxx@163.com
5、发送带有附件的邮件
echo “邮件正文,这是一封带有附件的邮件” | mail -a /root/anaconda-ks.cfg -s “testmail” xxx@163.com
-s 为标题
-a 指定附件
二、使用ssl协议发送邮件。
今日遇到一个项目使用阿里云。阿里云默认禁用了25端口,我们使用ssl 465端口发送邮件
1、同样启用postfix和mailx服务。
参照上面
2、请求数字证书
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i 163.crt cd /root/.certs/ #注意这块切换目录 certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i 163.crt certutil -L -d /root/.certs
3、配置mail.rc文件
vi /etc/mail.rc
在文件末尾新增
set from=xxx@163.com #发件邮箱 set smtp="smtps://smtp.163.com:465" #发送服务器,根据使用的邮箱设置 set smtp-auth-user= #账号 set smtp-auth-password= #密码 set smtp-auth=login #登录 set ssl-verify=ignore #ssl认证方式 set nss-config-dir=/root/.certs #证书所在目录
此处需注意,如果是网易游戏,密码为客户端授权密码。
4、验证
echo "这是使用 smtps 465端口发送的邮件" |mail -s "test465" xxx@163.com
猜你喜欢
- 2024-10-02 面试官:关于负载均衡你了解多少,知道哪些常用框架?
- 2024-10-02 你以为运维就是修电脑?大错特错!盘点一个高级运维的一天
- 2024-10-02 Linux基础架构学习 - MySQL,Git和Postfix - Day10
- 2024-10-02 IDEA工具篇:使用LiveTemplate模板、Postfix提示等提高编码效率
- 2024-10-02 关于 C++ 中的自增和自减操作符,你真的知道嘛?
- 2024-10-02 5.28 Postfix配置文件main.cf中常用参数介绍
- 2024-10-02 Linux基础架构学习 - MySQL,Git和Postfix - Day01
- 2024-10-02 CentOS7 - 配置Postfix以使用TLS(centos配置http)
- 2024-10-02 5.27 Postfix配置文件main.cf默认设置
- 2024-06-14 推荐 10 个不错的网络监视工具
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- jdk (81)
- putty (66)
- rufus (78)
- 内网穿透 (89)
- okhttp (70)
- powertoys (74)
- windowsterminal (81)
- netcat (65)
- ghostscript (65)
- veracrypt (65)
- asp.netcore (70)
- wrk (67)
- aspose.words (80)
- itk (80)
- ajaxfileupload.js (66)
- sqlhelper (67)
- express.js (67)
- phpmailer (67)
- xjar (70)
- redisclient (78)
- wakeonlan (66)
- tinygo (85)
- startbbs (72)
- webftp (82)
- vsvim (79)
本文暂时没有评论,来添加一个吧(●'◡'●)