我编写了一个脚本来创建基于SQL查询的HTML文件....有必要通过电子邮件发送HTML。我们的大多数高管使用黑莓,我想发送HTML文件作为正文。通过添加WebBrowser,然后让Web浏览器加载文件,然后使用下面的代码发送,我找到了一个关于完成此操作的方法。我面临的问题是,如果我完全自动化代码,它只会发送部分HTML文档,现在如果我添加一个按钮,并使其执行电子邮件功能,它会正确发送。我在几个不同的位置添加了一个等待函数,认为在发送电子邮件之前HTML没有完全创建可能是一个问题。我必须100%自动化。有没有办法可以使用.HTMLBody链接到存储在C:上的实际HTML文件:(实际路径是C:\ Turnover.html)。谢谢大家的帮助。
Public Sub Email() 昏暗的strdate 将iCfg视为对象 Dim iMsg As Object
strdate = Date.Today.TimeOfDay
iCfg = CreateObject("CDO.Configuration")
iMsg = CreateObject("CDO.Message")
With iCfg.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "xxxxx.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = """Turnover Report"" <TurnoverReports@xxxxx.com>"
.Update()
End With
With iMsg
.Configuration = iCfg
.Subject = "Turnover Report"
.To = "xxxxx@xxxxx.com"
'.Cc = ""
.HTMLBody = WebBrowserReportView.DocumentText
.Send()
End With
iMsg = Nothing
iCfg = Nothing
End Sub
答案 0 :(得分:1)
使用以下函数读取本地html文件。然后设置
TextBox2.Text = getHTML("C:\Turnover2.html")
以及
.HTMLBody = TextBox2.Text
Private Function getHTML(ByVal address As String) As String
Dim rt As String = ""
Dim wRequest As WebRequest
Dim wResponse As WebResponse
Dim SR As StreamReader
wrequest = WebRequest.Create(address)
wResponse = wrequest.GetResponse
SR = New StreamReader(wResponse.GetResponseStream)
rt = SR.ReadToEnd
SR.Close()
Return rt
End Function