编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

Linux发送外网邮件设置(含ssl协议)

wxchong 2024-10-02 01:25:57 开源技术 13 ℃ 0 评论

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

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表