0

I am trying to insert a hosted image to the body of my message. Here is what i have done so far:

Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
    Dim mailItem As Outlook.MailItem = TryCast(Inspector.CurrentItem, Outlook.MailItem)
    If Not (mailItem Is Nothing) Then
        If mailItem.EntryID Is Nothing Then
            mailItem.Subject = "Test"
            mailItem.Body = mailItem.Body + "<html><img src='http://example.com/pixel.php?to=" + mailItem.To + "></html>"
        End If
    End If
End Sub

The above inserts doesnt actually embed the image, it just adds the line:

<html><img src='http://example.com/pixel.php?to=" + mailItem.To + "></html>

To my my email body.

How can i get it embedded?

danyo
  • 5,686
  • 20
  • 59
  • 119

1 Answers1

2

Per my comment you are using MailItem.Body which is for plain text. Switch to HTMLBody

Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector
    Dim mailItem As Outlook.MailItem = TryCast(Inspector.CurrentItem, Outlook.MailItem)
    If Not (mailItem Is Nothing) Then
        If mailItem.EntryID Is Nothing Then
            mailItem.Subject = "Test"
            mailItem.HTMLBody = mailItem.HTMLBody + "<html><img src='http://example.com/pixel.php?to=" + mailItem.To + "></html>"
        End If
    End If
End Sub
Sorceri
  • 7,870
  • 1
  • 29
  • 38
  • Thanks @Sorceri. This seems to overwrite the signature that is automatically applied to new emails? – danyo Apr 24 '17 at 15:12
  • 1
    See here on how to keep the signature: http://stackoverflow.com/questions/8994116/how-to-add-default-signature-in-outlook – Sorceri Apr 24 '17 at 15:16