vba outlook嵌入图片网址

时间:2017-04-24 14:49:45

标签: vba outlook add-in

我正在尝试将托管图像插入到邮件正文中。以下是我到目前为止所做的事情:

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

以上插入实际上并没有嵌入图像,它只是添加了一行:

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

到我的电子邮件正文。

我如何嵌入它?

1 个答案:

答案 0 :(得分:2)

根据我的评论,您使用的是用于纯文本的MailItem.Body。切换到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