vba电子邮件嵌入图像不显示 [英] vba email embed image not showing

查看:436
本文介绍了vba电子邮件嵌入图像不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个奇怪的经历。我已经使用src = cid将电子邮件中嵌入了一个标志或图像的问题,发现它不会显示如果没有设置大小。



我有一个Access应用程序从...发送,但已经将其分解为下面的代码使用Excel。



但是



现在工作正常,如果我显示电子邮件,然后发送。根本不做任何事情。只需显示然后发送。



如果我直接从vba发送,图像将无法正常显示。附件符号显示,Outlook本身将图像内联,但说,gmail,wont。它不是gmails错误,因为attachmet符号显示在Outlook中。如果我显示然后发送,它不会。



我怀疑它仍然是尺寸或放置的东西。没有宽度部分,Outlook仍然会在正确的位置显示图像,但仍显示为附件。所以当你显示和按发送,那么我必须有另一个属性集或某事。我找不到什么!



希望有人可以帮助或有一个想法!我不是HTLM中最强的,所以这可能很简单...



谢谢



John

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

'创建新的Outlook MailItem
设置oApp = CreateObject(Outlook.Application)
设置oEmail = oApp.CreateItem(olMailItem)

'将图形添加到Outlook消息的附件
'根据需要更改图形路径
设置colAttach = oEmail.Attachments
设置oAttach = colAttach.Add(C:\temp\logo.jpg)
oEmail.Close olSave

'将src属性更改为'cid:您的图片文件名'
发送后会改为正确的cid。
oEmail.HTMLBody =< BODY>< IMG src =cid:logo.jpgwidth = 200< / BODY>
oEmail.Save
oEmail.To =someemailtogoinhere@gmail.com
oEmail.Subject =test
oEmail.Display
'oEmail.Send

Set oEmail = Nothing
Set colAttach = Nothing
设置oAttach = Nothing
设置oApp = Nothing
End Sub


解决方案

只是发布工作的简单形式的代码。非常感谢@Eugene Astafiev。

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

Dim olkPA As Outlook.PropertyAccessor

Const PR_ATTACH_CONTENT_ID =http ://schemas.microsoft.com/mapi/proptag/0x3712001F

'创建新的Outlook MailItem
设置oApp = CreateObject(Outlook.Application)
设置oEmail = oApp.CreateItem(olMailItem)
'将图形添加到Outlook消息的附件
'根据需要更改图形路径
设置colAttach = oEmail.Attachments
设置oAttach = colAttach.Add C:\temp\logo.jpg)
设置olkPA = oAttach.PropertyAccessor

olkPA.SetProperty PR_ATTACH_CONTENT_IDlogo.jpg

oEmail关闭olSave
'将src属性更改为'cid:您的图片文件名'
'将被更改为正确的cid发送时。
oEmail.HTMLBody =< BODY>< IMG src =cid:logo.jpg>< / BODY>

oEmail.Save
oEmail.To =someemail@gmail.com
oEmail.Subject =test
oEmail.Send

设置oEmail = Nothing
设置colAttach = Nothing
设置oAttach = Nothing
设置oApp = Nothing

End Sub


I have an odd experience here. I have had loads of problems embedding a logo or image to emails using the src=cid... found out it wont show if not setting size for example.

I have an Access application to send from, but have broken it down to the code below using Excel.

BUT

It now works fine, if I display the email and then send it. Not doing anything else at all. Just display then send.

If I send directly from vba, the image will not display properly. The attachment symbol shows and Outlook itself will put the image inline, but say, gmail, wont. It's not gmails fault, as the attachmet symbol shows in Outlook. It doesn't if I display and then send.

I suspect it's still something with sizing or placing. Without the width part, Outlook will still show the image at correct place, but still show as attachment. So when you display and press send then there must me another attribute set or something. I cannot find out what!

Hope someone can help or has an idea! I'm not the strongest in HTLM, so it's probably something simple...

Thanks

John

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

    'create new Outlook MailItem
    Set oApp = CreateObject("Outlook.Application")
    Set oEmail = oApp.CreateItem(olMailItem)

    'add graphic as attachment to Outlook message
    'change path to graphic as needed
    Set colAttach = oEmail.Attachments
    Set oAttach = colAttach.Add("C:\temp\logo.jpg")
    oEmail.Close olSave

    'change the src property to 'cid:your picture filename'
    'it will be changed to the correct cid when its sent.
    oEmail.HTMLBody = "<BODY><IMG src=""cid:logo.jpg"" width=200> </BODY>"
    oEmail.Save
    oEmail.To = "someemailtogoinhere@gmail.com"
    oEmail.Subject = "test"
    oEmail.Display
    'oEmail.Send

    Set oEmail = Nothing
    Set colAttach = Nothing
    Set oAttach = Nothing
    Set oApp = Nothing
End Sub

解决方案

Just to post the simple form of code that works. Big thanks to @Eugene Astafiev.

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

    Dim olkPA As Outlook.PropertyAccessor

    Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001F"

    'create new Outlook MailItem
    Set oApp = CreateObject("Outlook.Application")
    Set oEmail = oApp.CreateItem(olMailItem)
    'add graphic as attachment to Outlook message
    'change path to graphic as needed
    Set colAttach = oEmail.Attachments
    Set oAttach = colAttach.Add("C:\temp\logo.jpg")
    Set olkPA = oAttach.PropertyAccessor

    olkPA.SetProperty PR_ATTACH_CONTENT_ID, "logo.jpg"

    oEmail.Close olSave
    'change the src property to 'cid:your picture filename'
    'it will be changed to the correct cid when its sent.
    oEmail.HTMLBody = "<BODY><IMG src=""cid:logo.jpg""> </BODY>"

    oEmail.Save
    oEmail.To = "someemail@gmail.com"
    oEmail.Subject = "test"
    oEmail.Send

    Set oEmail = Nothing
    Set colAttach = Nothing
    Set oAttach = Nothing
    Set oApp = Nothing

End Sub

这篇关于vba电子邮件嵌入图像不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆