linux 下expect 实现自动登入smtp服务器并发送邮件

本文介绍如何使用Shell脚本结合Expect工具实现在Linux环境下自动登录SMTP服务器,并发送邮件告警的功能。该方法适用于系统监控场景,在检测到异常时能够自动通知管理员。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于想实现系统运行情况监控,发现在异常后能自动登入到公司的smtp服务器,然后发送告警到指定的邮箱 :D 在此做个笔记
经过搜罗用shell实现了下自动登入smtp服务器并发送邮件,需要linux上安装了expect

#!/usr/bin/expect -f
spawn telnet smtp.xxx.com 25
expect "])"
send "helo 163\r"
expect "250 OK"
send "auth login\r"
expect "334*"
send "用户名base64编码后\r"
#if you don't how to get your base64 encode,reference note 1 on the bottom.
expect "334*"
send "密码base64编码后\r"
expect "235*"
send "mail from:<xxxxxxxx@163.com>\r"
expect "250*"
send "rcpt to:<xxxxxx@qq.com>\r"
expect "250*"
send "data\r"
expect "354*"
send "from:xxxxxxx@163.com\r"
send "to:xxxxxxx@qq.com\r"
send "subject:server error\r"
send "MIME-Version:1.0\r"
send "content-type:text/plain\r"
send "服务器挂掉了\r"
send ".\r"
expect "250*"
send "quit\r"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值