返回列表 发帖

[问题求助] 有关VBS 自动发MAIL的问题询问

在VBS中有关MAIL的语句
MailObject.Subject = " "

MailObject.Textbody = "  "     ###这行附加的字符可以是中文的吗?我测试用中文的会出错,若想用中文要如何写呢?

MailObject.AddAttachment "d:\vbs_testall.txt"   ###这行路径可以是中文的吗?

有谁测试过请告知谢谢!!!

回复 1# depsyq

以下是我使用过的实例
' 用 ServerXMLHTTP 从 api.hostip.info 或 ip138 获取 IP 地址
Dim WinHttpReq
Set WinHttpReq = CreateObject("Msxml2.ServerXMLHTTP")
' WinHttpReq.Open "GET", "http://iframe.ip138.com/ic.asp"
WinHttpReq.Open "GET", "http://api.hostip.info/get_html.php"
WinHttpReq.Send
'正则表达式解析出外网IP
Dim MyRegExp
Set MyRegExp = CreateObject("VBScript.RegExp")
MyRegExp.Pattern = "((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)"
MyRegExp.IgnoreCase = True
MyRegExp.Global = True
Dim Matches
Set Matches = MyRegExp.Execute(WinHttpReq.ResponseText)
MsgBox Matches.Item(0).Value
URL_HOMEPAGE = "http://" & Matches.Item(0).Value
' SendEmail
NameSpace = "http://schemas.microsoft.com/cdo/configuration/"
Set Email = CreateObject("CDO.Message")
Email.From = "neorobin@163.com"
Email.To = "neorobin@163.com"
Email.Subject = "我的 IP 地址"
Email.HTMLBody = "<a href=""" & URL_HOMEPAGE & """" & " target=""_blank"">" & URL_HOMEPAGE & "</a><br>最后更新: " & now()
Email.AddAttachment "D:\桌面\TEST.TXT"
With Email.Configuration.Fields
    .Item(NameSpace&"sendusing") = 2
    .Item(NameSpace&"smtpserver") = "smtp.163.com" 'smtp服务器地址
    .Item(NameSpace&"smtpserverport") = 25
    .Item(NameSpace&"smtpauthenticate") = 1
    .Item(NameSpace&"sendusername") = "neorobin"
    .Item(NameSpace&"sendpassword") = "******"
    .Update
End With
Email.Send
set WinHttpReq = nothing
set MyRegExp = nothing
set Matches = nothing
set Email = nothingCOPY

TOP

第 31 行 改成
Email.TEXTBody = "最后更新: " & now()COPY
一样发送成功

TOP

set WinHttpReq = nothing
set MyRegExp = nothing
set Matches = nothing
set Email = nothing


这些什么意思

TOP

回复 4# depsyq


清理对象, 对此的必要性, 方式, 我并没有认识.

此文谈到这个问题
http://blogs.msdn.com/b/ericlipp ... cts-to-nothing.aspx

TOP

返回列表