linux利用telnet调用远程smtp服务发送邮件(原创)

linux下有很多地方需要发送邮件给管理员,比如系统资源使用情况、磁盘空间预警、重要数据自动备份等。

通常情况下,我们会采用mail命令发送邮件,但前提是系统安装了sendmail且正常配置。

最近入手了vps,简化的linux,很多功能被阉割不能调用mail命令,于是想到了利用telnet调用远程smtp服务发送邮件(smtp.163.com)

以下是实现的shell代码:

#!/bin/sh

send_mail()

{

  (for i in "ehlo luocheng" "AUTH LOGIN" "username" "userpwd" "MAIL FROM:<${1}>" "RCPT TO:<${2}>" "data";

   do

     sleep 1

     echo ${i}

     sleep 2

   done

   echo "from:<${1}>"

   echo "subject:${3}"

   echo "to:<${2}>"

   echo ""

   echo "${4}"

   echo "."

   sleep 2

   echo "QUIT")|telnet ${5} ${6}

}

#调用并传入参数

send_mail "luocheng@163.com" "5456588@qq.com" "test" "ok!" "smtp.163.com" "25"

注意,函数中的username和userpwd需要base64加密

最新评论:

no.10255 xgmu2tao 188.143.232.32 2016-06-08 14:12

Your articles are for when it abyelutols, positively, needs to be understood overnight.

no.3975 guozheng198577 118.186.139.199 2013-12-27 22:12

脚本写的不错,直接copy即可执行,Good

发表评论:

邮箱: