shell中使用expect发送邮件

一、telnet模拟发邮件

[root@sc_10_9_21_24_ucloud_jump ~]# telnet mx3.qq.com 25
Trying 58.251.110.111...
Connected to mx3.qq.com.
Escape character is '^]'.
220 newxmmxszb75.qq.com MX QQ Mail Server.
helo abc.cn
250-newxmmxszb75.qq.com-100.65.28.199-44465081
250-SIZE 73400320
250 OK
mail from:<x@abc.cn>
250 OK.
rcpt to:<448252153@qq.com>
250 OK 1
data
354 End data with <CR><LF>.<CR><LF>.
wo de
.
250 Ok: queued as 
quit
221 Bye.

二、基于expect 脚本实现

j(1)expect环境安装:https://www.cnblogs.com/operationhome/p/9154055.html

 (2)   vim expect_sendmail.ex


#!/usr/bin/expect

set smtp_server mx3.qq.com
set smtp_port 25
set sender x@abc.cn
set to  448252153@qq.com
spawn  telnet $smtp_server $smtp_port
expect "220"
send  "helo abc.cn\r"
expect "250"
send "mail from:<$sender>\r"
expect "250"
send "rcpt to:<$to>\r"
expect "250"
send "data\r"
expect "354"
send "subject:来自xjm\r"
send "\r"
send "这是个测试邮件\r"
send ".\r"
expect "250"
send "quit\r"

(3) 执行

     chmod 755 expect_sendmail.ex

    ./expect_sendmail.ex

 

https://web.sendcloud.net

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值