linux 下expect 实现自动登入smtp服务器并发送邮件
由于想实现系统运行情况监控,发现在异常后能自动登入到公司的smtp服务器,然后发送告警到指定的邮箱 在此做个笔记
经过搜罗用shell实现了下自动登入smtp服务器并发送邮件,需要linux上安装了expect
#!/usr/bin/expect -fspawn telnet smtp.xxx.com 25expect "])"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"