现在的位置: 首页 > 综合 > 正文

◎简单的邮件发送客户端-hta

2013年09月11日 ⁄ 综合 ⁄ 共 5073字 ⁄ 字号 评论关闭

在网络中有pop3smtp两种邮件服务器,一般情况下,pop3邮件服务器一般用来接收邮件,而smtp服务器用来发送邮件。就是因为各大网站提供了这两种类型的邮件服务器,使我们能够注册并使用他们邮件服务。尽管现在有着各种各样的邮件客户端,但自己编写一个小小的程序来完成一些简单的工作,还是让自己心中充满了自豪感。感谢微软为我们提供了cdo.message对象(它对应的动态链接库文件是C:/WINDOWS/system32/

cdosys.dll),使我们能够使用脚本来完成发送邮件的工作。

CDO.Message对象常见的属性有:

Form-发件人邮件地址;

To-收件人邮件地址;

Subject-邮件标题;

TextBody-邮件内容;

HtmlBody-html格式的邮件主体,例如:"<html><body>" + "邮件信息" + "</body></html>";

常见的方法有:

AddAttachment()-添加附件;

Send()-发送邮件等。

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<html>

<head>

<meta http-equiv="content-type" content="text/html; charset=GB2312">

<meta name="generator" content="Web Page Maker V2">

<style type="text/css">

/*----------Text Styles----------*/

.ws6 {font-size: 8px;}

.ws7 {font-size: 9.3px;}

.ws8 {font-size: 11px;}

.ws9 {font-size: 12px;}

.ws10 {font-size: 13px;}

.ws11 {font-size: 15px;}

.ws12 {font-size: 16px;}

.ws14 {font-size: 19px;}

.ws16 {font-size: 21px;}

.ws18 {font-size: 24px;}

.ws20 {font-size: 27px;}

.ws22 {font-size: 29px;}

.ws24 {font-size: 32px;}

.ws26 {font-size: 35px;}

.ws28 {font-size: 37px;}

.ws36 {font-size: 48px;}

.ws48 {font-size: 64px;}

.ws72 {font-size: 96px;}

.wpmd {font-size: 13px;font-family: 'Arial';font-style: normal;font-weight:

normal;}

/*----------Para Styles----------*/

DIV,UL,OL /* Left */

{

margin-top: 0px;

margin-bottom: 0px;

}

</style>

<HTA:APPLICATION

       APPLICATIONNAME="http://hi.baidu.com/xuejinglan"

       border="thin"

       borderstyle="normal"

       caption="yes"

       icon="c.ico"

       caption="no"

       maximizebutton="no"

       minimizebutton="yes"

       showintaskbar="yes"

       singleinstance="yes"

       sysmenu="yes"

       SCROLL="no"

       version="1.0"

       windowState="normal"

>

</head>

<script language="vbscript">

Sub Window_onLoad

window.resizeTo 325,470

End Sub

sub open

set objFile = CreateObject("SAFRCFileDlg.FileOpen")

intRet = objFile.OpenFileOpenDlg

if intret then

formtext3.value=objFile.filename

else

msgbox "您没有选取文件!"

end if

end Sub

sub send

NameSpace = "http://schemas.microsoft.com/cdo/configuration/"

Set Email = CreateObject("CDO.Message")

Email.From = "xuejinglan@sohu.com"

if formtext1.value="" then

formtext1.value="xuejinglan@sohu.com"

Email.To=formtext1.value

else

Email.To = formtext1.value

end if

if formtext2.value="" then

formtext2.value="无主题邮件"

Email.Subject =formtext2.value

else

Email.Subject =formtext2.value

end if

if textarea1.value="" then

textarea1.value="邮件主体无内容"

Email.Textbody = textarea1.value

else

Email.Textbody = textarea1.value

end if

If formtext3.value<>"" Then Email.AddAttachment formtext3.value

With Email.Configuration.Fields

//比较特殊的是:cdo.message设置服务器的参数比较特殊,我们将在代码中一一加以说明,(据微软称:他们疑惑为何需要连接到 Microsoft

来发送电子邮件。事实是,不会真的连接到 Microsoft;这些 URI 只是属性而已。为何要怎样引用呢?老实说,我们不清楚。但是别担心:您的邮件不会通过

Microsoft 进行路由,而且这里的人也不会阅读您的信件。相信我们,我们自己的电子邮件已经让我们够头疼了,没有时间去读别人的邮件。)

.Item(NameSpace&"sendusing") = 2 // '1 代表使用 local smtp, 2 为外部 smtp

.Item(NameSpace&"smtpserver") = "smtp.sohu.com" // 自己的邮件的SMTP 服务器地址

.Item(NameSpace&"smtpserverport") = 25  // '端口 25

.Item(NameSpace&"smtpauthenticate") = 1  // SMTP验证,一般都是1,代表普通

.Item(NameSpace&"sendusername") = "xxxxxx"   //自己的邮件的帐号

.Item(NameSpace&"sendpassword") = "*******"    //自己的邮件的密码

.Update

End With

Email.Send

Set Email=Nothing

end sub

</script>

<body bgcolor="0099ff">

<div id="text1" style="position:absolute; overflow:hidden; left:53px; top:9px;

width:214px; height:32px; z-index:0"><div

class="wpmd">

<div><font class="ws20" color="#FF0000"

face="华文行楷">VBS&#37038;&#20214;&#23458;&#25143;&#31471;</font></div>

</div></div>

<div id="marquee1" style="position:absolute; overflow:hidden; left:0px;

top:58px; width:303px; height:20px; z-index:1">

<marquee width="303" height="20">

<div class="wpmd">

<div><font class="ws20" color="#0000FF" face="华文行楷"> </font><font

color="#0000FF" face="华文行

">&#20020;&#27774;&#24066;&#22806;&#20107;&#26053;&#28216;&#23616;&#34203;&#38742;&#28572;&#35774;&#35745;</font></div>

</div></marquee>

</div>

<div id="text2" style="position:absolute; overflow:hidden; left:1px; top:94px;

width:107px; height:22px; z-index:2"><div

class="wpmd">

<div><font class="ws14"

face="华文新魏">&#25910;&#20214;&#20154;&#22320;&#22336;:</font></div>

</div></div>

<div id="text3" style="position:absolute; overflow:hidden; left:1px; top:116px;

width:107px; height:22px; z-index:3"><div

class="wpmd">

<div><font class="ws14" face="华文新魏">&#20027; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

&#39064;:</font></div>

</div></div>

<div id="text4" style="position:absolute; overflow:hidden; left:1px; top:143px;

width:107px; height:22px; z-index:4"><div

class="wpmd">

<div><font class="ws14" face="华文新魏">&#38468; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

&#20214;:</font></div>

</div></div>

<input name="formtext1" type="text"  value="xuejinglan@sohu.com"

style="position:absolute;width:200px;left:106px;top:91px;z-

index:5">

<input name="formtext2" type="text"

style="position:absolute;width:200px;left:106px;top:113px;z-index:6">

<input name="formtext3" type="text"

style="position:absolute;width:160px;left:106px;top:140px;z-index:7">

<input name="formbutton1" type="button" value="..."

style="position:absolute;left:273px;top:140px;z-index:8" onclick="open">

<textarea name="textarea1"

style="position:absolute;width:302px;height:207px;left:4px;top:174px;z-index:9"></textarea>

<input name="formbutton2" type="button" value="                     "

style="position:absolute;left:3px;top:393px;z-

index:10" onclick="send">

</body>

</html>

不过可惜的是,我不知道如何才能判断邮件发送成功,不知道谁能指教一下。

 

抱歉!评论已关闭.