本文介绍了为什么我的图片嵌入到HTML电子邮件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在VBA中运行代码,发送HTML电子邮件,并尝试在电子邮件中嵌入图像。我有以下代码:

I'm trying to run code in VBA that will send out HTML emails and am trying to embed an image within the email. I have the following code to do so:

Sub EmailImage()

Dim oApp As Outlook.Application
Dim oEmail As MailItem
Dim colAttach As Outlook.Attachments
Dim oAttach As Outlook.Attachment

Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(olMailItem)
Set colAttach = oEmail.Attachments
Set oAttach = colAttach.Add("C:\Users\User1\Documents\thumbs-up.jpg")
oEmail.Close olSave
oEmail.To = "[email protected]"
oEmail.HTMLBody = "<IMG alt='' hspace=0 src='cid:thumbs-up.jpg' align=baseline border=0>&nbsp;</BODY>"
oEmail.Send
Set oEmail = Nothing
Set colAttach = Nothing
Set oAttach = Nothing
Set oApp = Nothing

End Sub

但是会发生什么是图像被附加,但是在其中有一个红十字的框,其中的图像应该是,如下图所示:

But what happens is that the image gets attached but there's a box with a red cross in it where the image should be, as is shown in the below image:

我已经尝试了以下代码:

I have tried the following adapton to the code:

Sub EmailImage()
Dim oApp As Outlook.Application
Dim oEmail As MailItem
Dim colAttach As Outlook.Attachments
Dim oAttach As Outlook.Attachment

Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(olMailItem)
Set colAttach = oEmail.Attachments
Set oAttach = colAttach.Add("C:\Users\User1\Documents\thumbs-up.jpg")

oAttach.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyCid")

oEmail.Close olSave
oEmail.To = "[email protected]"
oEmail.HTMLBody = "<IMG alt='' hspace=0 src='cid:MyCid' align=baseline border=0>&nbsp;</BODY>"
oEmail.Send
Set oEmail = Nothing
Set colAttach = Nothing
Set oAttach = Nothing
Set oApp = Nothing
End Sub

但是,这给我错误的编译错误:expected =在行$ oAttach.PropertyAccessor。 SetProperty(http://schemas.microsoft.com/mapi/proptag/0x3712001F,MyCid)所以我试图拿出,MyCid)并将电子邮件中的代码更改为 oEmail.HTMLBody =< IMG alt =''hspace = 0 src ='cid:thumbs-up.jpg'align = baseline border = 0>& nbsp;< / BODY>,使其看起来像这样:

But this gives me the error "Compile error: expected =" on the line oAttach.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyCid") so I tried to take out the , "MyCid") and changed the code in the email to just oEmail.HTMLBody = "<IMG alt='' hspace=0 src='cid:thumbs-up.jpg' align=baseline border=0>&nbsp;</BODY>" again, so that it looks like this:

Sub EmailImage()

Dim oApp As Outlook.Application
Dim oEmail As MailItem
Dim colAttach As Outlook.Attachments
Dim oAttach As Outlook.Attachment

Set oApp = CreateObject("Outlook.Application")
Set oEmail = oApp.CreateItem(olMailItem)
Set colAttach = oEmail.Attachments
Set oAttach = colAttach.Add("C:\Users\User1\Documents\thumbs-up.jpg")
oAttach.PropertyAccessor.SetProperty ("http://schemas.microsoft.com/mapi/proptag/0x3712001F")

oEmail.Close olSave
oEmail.To = "[email protected]"
oEmail.HTMLBody = "<IMG alt='' hspace=0 src='cid:thumbs-up.jpg' align=baseline border=0>&nbsp;</BODY>"
oEmail.Send
Set oEmail = Nothing
Set colAttach = Nothing
Set oAttach = Nothing
Set oApp = Nothing

End Sub

但是我现在得到错误编译错误:参数不可选它指向 .SetProperty 部分行 oAttach.PropertyAccessor.SetProperty(http://schemas.microsoft.com/ map / proptag / 0x3712001F)

But I now get the error Compile error: argument not optional with it pointing at the .SetProperty part of the line oAttach.PropertyAccessor.SetProperty ("http://schemas.microsoft.com/mapi/proptag/0x3712001F").

请注意,我使用的是Windows 7,Microsoft Excel 2010和Microsoft Outlook 2010。 >

Please note that I am using Windows 7, Microsoft Excel 2010 and Microsoft Outlook 2010.

推荐答案

好的,在Googling之后,出现错误消息Compile error:expected =,更改行:

Ok, after Googling the error message "Compile error: expected =", the changing the line:

oAttach.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyCid")

To:

Call oAttach.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyCid")

工作。

我从

感谢您的所有评论和答案。

Thank you for all your comments and answers.

这篇关于为什么我的图片嵌入到HTML电子邮件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 22:11