使用JScript发送邮件

上一篇 / 下一篇  2007-10-10 22:21:25 / 个人分类:JScript

使用Jscrīpt发送邮件

M%A c/[ P(v#_0

 51Testing软件测试网la0xu:`a,M&D|r

陈能技51Testing软件测试网$k7IF+n g\&i9HZH

2007-10-1051Testing软件测试网 h`9M| M/I ?

 51Testing软件测试网 p$E/Ft%F8Y5w

CDOCollaboration Data Objects)对象,以前的版本叫OLE MessageActive Message。是个高层次的COM对象,可用于简单地访问邮件系统、发送邮件。在Jscrīpt中可以方便地调用此对象进行消息发送。51Testing软件测试网f\3z Ai J7o3{uv)]

 

JA!k$qA&bq0

要利用CDO发送邮件,首先必须创建CDOMessageConfiguration对象。例如:

v3l a"@2KB.b0

var iMsg,iConf;51Testing软件测试网1h6yNp2v-`

iMsg=Wscrīpt.CreateObject("CDO.Message");51Testing软件测试网.J,wa1FjEA"Qo

iConf=Wscrīpt.CreateObject("CDO.Configuration");51Testing软件测试网f!Se1e'gf0O

 51Testing软件测试网C}R9p8kM

创建CDO.Configuration对象后,需要设置邮件服务器的端口、用户帐号等相关信息,例如:51Testing软件测试网e4V.E+ew.X }3EI

 51Testing软件测试网~*A&w(X UFA,S;b,Z:T

iConf.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")=2;51Testing软件测试网 _T }5w!Hd] Tn

iConf.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver")="tr-mail";51Testing软件测试网"V_1aH5D XI

iConf.Fields("http://schemas.microsoft.com/cdo/configuration/serverport")="25";51Testing软件测试网'|#Er$\Ty$l4W

iConf.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1;

Y WeUyd+`,F0

iConf.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")="username";51Testing软件测试网%^X{GU{rp)O

iConf.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")="password";51Testing软件测试网A{cLR D"x0br

iConf.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")=1;51Testing软件测试网+H C7tU5f7S

iConf.Fields.Update();

NbGkS |+W!o;l0

 51Testing软件测试网"S_6_%f2l"V%XKD'c

通过CDOMessage对象设置邮件主题、附件、发送人等信息,例如:51Testing软件测试网oF4L%x^7oN&bu

 

h JDk$a0

iMsg.Configuration = iConf;

.S9x uEeTy0

iMsg.To = "SendToUserName";

} U$?.Py} x0

iMsg.From = "SendFormUserName";51Testing软件测试网~[*D8yE {9S

iMsg.Subject = "Subject";51Testing软件测试网'lW_ jg/@[)Ihm~qZ(e

iMsg.AddAttachment("C:\test.txt");

_6CuR X!FYy!f4M0

iMsg.TextBody = "";

-V'D.X1`.]5C:H3l#PW4e0

iMsg.Send();

e*t w;\T#Q td0

 

MU~/G M6_x0

最后,通过Send方法即可发送邮件。51Testing软件测试网 wk:sb$o*W_#Yb

 

3b U8T.`7oq0

CDO的消息发送能力在自动化测试中可能会用到,尤其是在构建自动化测试框架时可以利用它来发送测试结果,也可用在每日构建中用于通知项目组成员构建的相关信息。51Testing软件测试网B%t,bLZ;H4F%R,S


TAG: 脚本 JScript 邮件 每日构建

 

评分:0

我来说两句

Open Toolbar