1

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.

0m3r
  • 12,286
  • 15
  • 35
  • 71
Brian Cox
  • 46
  • 4
  • Couldn't find it by searching, but this user had the same issue http://stackoverflow.com/questions/34046708/ which appeared in the "related" questions list, so i'll work through the suggestions/advice in there – Brian Cox May 12 '17 at 22:16
  • Try changing to `Set Outl = CreateObject("Outlook.Application")` and `Set omsg = Outl.CreateItem(0)` Then use `omsg.send` – 0m3r May 12 '17 at 23:21

1 Answers1

0

Most probably you get a security issue. "Security" in this context refers to the so-called "object model guard" that triggers security prompts and blocks access to certain features in an effort to prevent malicious programs from harvesting email addresses from Outlook data and using Outlook to propagate viruses and spam. These prompts cannot simply be turned off, except in Outlook 2007 and later with an anti-virus application running. This page discusses strategies for avoiding the security prompts:

  1. Develop a COM add-in which doesn't trigger security issues.
  2. You can use the Outlook Security Manager component for disabling security prompts in Outlook.
  3. Use a low-level API on which Outlook is based on and which doesn't trigger security issues/prompts - Extended MAPI or any other third-party wrapper around that API (such as Redemption).
  4. Deploy Outlook security settings via GPO.
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45