以下是我生成电子邮件并将其显示给用户的代码:
Imports Outlook = Microsoft.Office.Interop.Outlook
Private Function ReadSignature(sigName As String) As String
Dim oFSO, oTextStream As Object
Dim appDataDir, sig, sigPath, fileName As String
appDataDir = Environ("APPDATA") & "\Microsoft\Signatures"
sigPath = appDataDir & "\" & sigName
oFSO = CreateObject("Scripting.FileSystemObject")
oTextStream = oFSO.OpenTextFile(sigPath)
sig = oTextStream.ReadAll
' fix relative references to images, etc. in sig
' by making them absolute paths, OL will find the image
fileName = Replace(sigName, ".htm", "") & "_files/"
sig = Replace(sig, fileName, appDataDir & "\" & fileName)
ReadSignature = sig
End Function
Private Sub Email()
Dim INC As String
INC = wb1.Document.GetElementById("arid_WIN_2_1000000161").InnerText
Dim sig As String
' MainSig.htm is the name you gave your signature in the OL Options dialog
sig = ReadSignature("MainSig.htm")
Dim Outl As Object
Outl = CreateObject("Outlook.Application")
If Outl IsNot Nothing Then
Dim omsg As Object
omsg = Outl.CreateItem(0)
omsg.To = TextBox35.Text
omsg.cc = TextBox37.Text
omsg.subject = INC & TextBox38.Text
omsg.HTMLBody = "<p>" & TextBox40.Text & "</p><p>" & TextBox41.Text & "</p><p>" & "<p>INC# : " & INC & "<br/>TMS ID: " & TextBox2.Text & TextBox4.Text & "</p><p>Issue : " & "<br/>Resulting in: " & ComboBox6.Text & "<br/>Issue Resolved?: " & TextBox29.Text & "<br/>User error?: " & TextBox30.Text & "</p><p>Person reporting (Or name Of caller): " & TextBox1.Text & "<br/>Reported Source: " & ComboBox2.Text & "<br/>INC# Provided to customer: " & TextBox21.Text & "<br/>Date And Time: " & DateTimePicker2.Value & "<br />(MM/DD/YYYY HH:MM) " & ComboBox1.Text & "</p><p>Site(s) affected:<br />" & TextBox5.Text & "<br/>" & TextBox6.Text & "</p><p>Additional notes: <br />" & TextBox3.Text & "</p><p>" & TextBox24.Text & "<br /></p><p>Impact : " & ComboBox3.Text & "<br />Urgency: " & ComboBox4.Text & "<br /></p><p>" & sig
omsg.Display(True)
End If
End Sub
这非常适合用户需要升级故障单,因为它允许他们在发送之前添加任何额外的备注,但是我试图让它将每个创建的故障单(无论是否已升级)发送给我们主邮箱以及任何升级电子邮件(最好是在后台完成,不依赖于用户单击发送而不是仅仅关闭它,因为我知道其中一些会这样做。)
问题是,当我将 omsg.Display(True)更改为 omsg.send 时会抛出异常并失败
我甚至尝试离开 omsg.Display(True)并在下一行添加 omsg.send ,但这只是显示消息然后抛出异常
我已经在某处读到,它可能是一个旨在阻止自我复制病毒的群组政策,通过电子邮件将自己通过电子邮件发送给地址簿中的所有人,如果是这种情况,您是否可以想到解决方法?
提前谢谢。
答案 0 :(得分:0)
很可能您遇到了安全问题。在此上下文中的“安全性”是指所谓的“对象模型防护”,它触发安全提示并阻止对某些功能的访问,以防止恶意程序从Outlook数据中收集电子邮件地址并使用Outlook传播病毒和垃圾邮件。除了在Outlook 2007及更高版本中运行防病毒应用程序之外,不能简单地关闭这些提示。这个page讨论了避免安全提示的策略: