从 Excel VBA 发送格式化的 Lotus Notes 富文本电子邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3263343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending formatted Lotus Notes rich text email from Excel VBA
提问by Riccardo Baldinotti
While trying to use the hints in your answer at
在尝试使用答案中的提示时
Sending formatted Lotus Notes rich text email from Excel VBA
I could do almost everything I needed: write multiple lines with data from a database of mine, formatting the body by mean of html code, with links and formatted text.
我几乎可以做我需要的一切:用我的数据库中的数据写多行,通过 html 代码格式化正文,带有链接和格式化文本。
I also need to put an image in the mail body, but the html code "img src="etc. does not work, maybe because the image is located on my pc and is not reached by the recipients. I need to find a way to embed the image just like I would do by mean of the Lotus menus. In my Italian Lotus Notes 7, there is a Create menu with an Image option, I find the image, click OK and it is done.
我还需要在邮件正文中放置一个图像,但是 html 代码“img src="etc. 不起作用,可能是因为图像位于我的电脑上并且收件人无法访问。我需要找到一种方法来嵌入图像,就像我通过 Lotus 菜单所做的那样。在我的意大利语 Lotus Notes 7 中,有一个带有图像选项的创建菜单,我找到了图像,单击确定就完成了。
That's what I wish to do with my code, please tell me it's possible! :-)
这就是我希望用我的代码做的事情,请告诉我这是可能的!:-)
Thanks in advance.
提前致谢。
Riccardo Baldinotti, Italy
里卡尔多·巴尔迪诺蒂,意大利
回答by Dr. belisarius
Hereyou can find the complete code. It's too large to paste here, so I'm copying just a few lines to show the idea:
在这里你可以找到完整的代码。粘贴在这里太大了,所以我只复制了几行来展示这个想法:
If (bSetImages) Then
For iImageIndex = 0 To Ubound(imageFilePaths)
' Get the image file path and content id (cid).
strImagePath = Trim(imageFilePaths(iImageIndex))
If (strImagePath = "") Then Exit Sub
strImageCid = Trim(imageContentIds(iImageIndex))
If (strImageCid = "") Then Exit Sub
' Get the image context type.
If (StrContains(strImagePath, ".", True)) Then strImageExt = Strrightback(strImagePath, ".") Else strImageExt = ""
Select Case Lcase(strImageExt)
Case "gif": strImageType = "image/gif"
Case "jpg": strImageType = "image/jpg"
Case Else: strImageType = "image/gif"
End Select
' Add the image part.
Set mimeImage = mimeBody.CreateChildEntity()
Set mimeImageHeader = mimeImage.CreateHeader({Content-ID})
Call mimeImageHeader.SetHeaderVal("<" & strImageCid & ">")
Call stream.Open(strImagePath)
Call mimeImage.SetContentFromBytes(stream, strImageType & {;name="} + strImageCid + {"}, ENC_IDENTITY_BINARY)
Call stream.Close()
Next
End If
回答by Riccardo Baldinotti
At the address
在地址
I found a solution, and now my mail body has an image in it.
我找到了一个解决方案,现在我的邮件正文中有一个图像。
Here is my code.
这是我的代码。
Call stream.Open("<MY IMAGE PATH>")
Set body = MailDoc.CreateMIMEEntity '("memo")
Set richTextHeader = body.CreateHeader("Content-Type")
Call richTextHeader.SetHeaderVal("multipart/mixed")
Set mimeImage = body.CreateChildEntity()
strImageType = "image/jpeg" 'Other formats are "image/gif" "image/bmp"
Call mimeImage.SetContentFromBytes(stream, strImageType, ENC_IDENTITY_BINARY)
Call stream.Close
Regards
问候