Here is my code to generate an email and display it to the user:
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
This is great for when users need to escalate a ticket, as it allows them to add any extra notes before sending it, however I am trying to make it send a copy of every ticket created (whether escalated or not) to our main mailbox as well as any escalation emails (preferably it will be done in the background, without relying on the user clicking send rather than just closing it as i know some of them would).
The issue is when i change omsg.Display(True) to omsg.send it throws an exception and fails
I've even tried leaving omsg.Display(True) and adding omsg.send on the next line, but that just displays the message and then throws the exception
I've read somewhere that it could be a group policy designed to stop self replicating viruses emailing themselves to everyone in your address book, if this is the case can any of you think of a workaround?
Thank you in advance.