2020-02-17第12章、smtp(e-mail)

简单网络管理语言(Simple Network Management Language)是一种类自然语言的脚本语言,它采用snmp、telnet、ping、dns、arp、ssh、tcp、udp、web等协议访问网络设备,内置smtp协议用于告警等邮件的发送,支持excel、mysql、sqlite等3种方式进行网管数据的存取。

手册最新版:https://ladybirdsnml.github.io/snmlipv6utf8snmptelnetsshweb/snmldoc_utf8ipv6.html

第12章、smtp(e-mail)

  电子邮件(e-mail)是最流行的应用,简单邮件传送协议 SMTP (Simple Mail Transfer Protocol)用于发送电子邮件。在snml语言中,可用email来自动发送告警邮件、设备配置参数等。

1、 smtp语句分析

smtp.server {smtp.163.com} port {25} username {[email protected]} password {123456}

设置smtp邮件服务器的参数,服务器域名“smtp.163.com”,端口号“25”,登录邮箱名“[email protected]”,邮箱密码“123456”

smtp.subject {发送邮件测试} body {邮件正文}

填写邮件的标题和正文的值,在本示例中标题为“发送邮件测试”,正文为“邮件正文”

smtp.add attachment {C:\snmlipv6\excel\snml.xlsx}

邮件添加附件“C:\snmlipv6\excel\snml.xlsx”

smtp.send to {[email protected]}

发送邮件到邮件接受者邮箱“[email protected]

2、示例脚本[C:\snmlipv6\smtp\smtp_nms1.txt]

C:\snmlipv6\smtp\smtp_nms1.txt

001screen.text at point {250} {30} string {12. smtp Test: Send Mail}

002

003var {v_time} value datetime

004var {v_y} value {60}

005

006

007screen.text at point {10} {~v_y~} string {sina, Begin To Send A Mail: ~v_time~}

008

009smtp.server {smtp.sina.com} port {25} username {[email protected]} password {myPassword}

010smtp.subject {Test Send A Mail:~v_time~} body {Email Body%0a, Send Time: ~v_time~}

011smtp.add attachment {C:\snmlipv6\excel\snml.xlsx}

012smtp.add attachment {C:\snmlipv6\text\text99.txt}

013run.set loglevel {debug}

014smtp.send to {[email protected]}

015run.set loglevel {nolog}

016screen.text at point {300} {~v_y~} string {Send Mail End.}

017

018

019var {v_time} value datetime

020var {v_y} add number {20}

021

022screen.text at point {10} {~v_y~} string {126, Begin To Send A Mail: ~v_time~}

023

024smtp.server {smtp.126.com} port {25} username {[email protected]} password {myPassword}

025smtp.subject {Test Send A Mail:~v_time~} body {Email Body%0a, Send Time: ~v_time~}

026smtp.add attachment {C:\snmlipv6\excel\snml.xlsx}

027smtp.add attachment {C:\snmlipv6\text\text99.txt}

028run.set loglevel {debug}

029smtp.send to {[email protected]}

030run.set loglevel {nolog}

031screen.text at point {300} {~v_y~} string {Send Mail End.}

032

033

034var {v_time} value datetime

035var {v_y} add number {20}

036screen.text at point {10} {~v_y~} string {163,Begin To Send A Mail: ~v_time~}

037

038smtp.server {smtp.163.com} port {25} username {[email protected]} password {myPassword}

039smtp.subject {Test Send A Mail:~v_time~} body {Email Body%0a, Send Time: ~v_time~}

040smtp.add attachment {C:\snmlipv6\excel\snml.xlsx}

041smtp.add attachment {C:\snmlipv6\text\text99.txt}

042run.set loglevel {debug}

043smtp.send to {[email protected]}

044run.set loglevel {nolog}

045screen.text at point {300} {~v_y~} string {Send Mail End.}

046

047run.end

  脚本执行画面如下:

目录: 1、var 2、screen 3、snmp 4、telnet 5、text 6、if 7、loop 8、dns 9、ping 10、arp 11、excel 12、smtp 13、tcp 14、udp 15、ssh 16、web 17、mysql 18、sqlite 19、Run 20、sys 21、macro 附录1、全部语句

你可能感兴趣的:(2020-02-17第12章、smtp(e-mail))