VBS:调用URL传递HTML字符串参数以作为电子邮件发送

时间:2015-03-10 18:35:20

标签: vbscript

如何在不使用VBScript打开浏览器的情况下将多个变量传递给link / href?目标是根据URL上传递的参数保存/插入/更新,IIS Web服务器必须执行数据库更改而不是VBScript。 VBScript按计划运行,并且不希望每次执行时都在服务器上打开浏览器。

我的VBS代码如下:

Function HTMLEncode(Text)
    Dim i 
    Dim acode 
    Dim repl 
    HTMLEncode = Text 
    For i = Len(HTMLEncode) To 1 Step -1 
        acode = Asc(Mid(HTMLEncode, i, 1))
        Select Case acode 
            Case 32 
                repl = " " 
            Case 34 
                repl = """ 
            Case 38 
                repl = "&" 
            Case 60 
                repl = "<" 
            Case 62 
                repl = ">" 
            Case acode => 32 AND acode <= 127 
                ' don't touch alphanumeric chars 
            Case Else 
                repl = "&#" & CStr(acode) & ";" 
        End Select 
        If Len(repl) Then 
            HTMLEncode = Left(HTMLEncode, i - 1) & repl & Mid(HTMLEncode,+ 1) 
            repl = "" 
        End If 
    Next 
End Function 


strBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & _
  "<html>" & _
    "<head>" & _
    "<title>TEST</title>" & _
    "</head>" & _
    "<body bgcolor=""#FFFFFF"">" & _
    "<p> The user bla bla bla </p>" & _
    "<p><b> &nbsp;&nbsp;" & _
    "<br><br><br><br> This message is sent from an un-monitored mailbox, please do not reply.  " & _
    "</p>" & _
    "</body>" & _
    "</html>"

    strBody = HTMLEncode(strBody)

    myURL = "http://www.test.com/sendmail.asp?body=" & strBody

Set req = CreateObject("MSXML2.XMLHTTP.6.0")
req.Open "GET", myURL, False
req.Send

0 个答案:

没有答案