使用访问 vba 将图像嵌入到邮件正文中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16634599/
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
embed image into mail body using access vba
提问by Amro
I am currently using the code below to send out mails from access with an attachment. But i searched everywhere with no luck for a sokution to get the attachment embeded into the mail body itself. Anyone can help me out.
我目前正在使用下面的代码从带有附件的访问中发送邮件。但是我到处搜索都没有找到将附件嵌入到邮件正文中的sokution。任何人都可以帮助我。
Option Compare Database
Option Explicit
'Declare public object variables
Public mkfDoc As String
Public Subject, Attachment, Recipient, copyto, BodyText, UserName, SaveIt
Public Maildb As Object 'The mail database
Public MailDbName As String 'The current users notes mail database name
Public MailDoc As Object 'The mail document itself
Public AttachME As Object 'The attachment richtextfile object
Public Session As Object 'The notes session
Public EmbedObj As Object 'The embedded object (Attachment)
Public Function sendNotes(ByVal strTo As String, ByVal Attachment As String, ByVal strSubject As String, ByVal strBody As String)
'Set up the objects required for Automation into lotus notes
Subject = strSubject
'Attachment = "c:\foldername\filename.extension"
Recipient = Split(strTo, ",")
'Set bodytext for mail offer - language depends on field in offprofrm
BodyText = strBody
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.ISOPEN = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = BodyText
MailDoc.SAVEMESSAGEONSEND = True
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document + notify
MailDoc.PostedDate = NOW() 'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Function
回答by Knut Herrmann
A good way to create an email with included attachments in body field is to use the MIME format.
在正文字段中创建包含附件的电子邮件的一种好方法是使用 MIME 格式。
Set body = MailDoc.CreateMIMEEntity("Body")
...
Have a look at http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/creating-a-mime-email-with-attachmentand https://stackoverflow.com/a/2514633/2065611how to do it.
看看http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/creating-a-mime-email-with-attachment和https://stackoverflow.com/a/2514633/2065611如何去做吧。
回答by user3190020
First you need to create an outlook mail object, then, write the mail body (in html) with the appropriate <img src='myfile.jpg'> tag. Please note following points :
- embedded images must be save on your computer (as a jpg file or png file) ;
- Since outlook 2013, embedded images must be attached to the email as well.
首先,您需要创建一个 Outlook 邮件对象,然后使用适当的 <img src='myfile.jpg'> 标记编写邮件正文(以 html 格式)。请注意以下几点:
- 嵌入的图像必须保存在您的计算机上(作为 jpg 文件或 png 文件);
- 从 Outlook 2013 开始,嵌入的图像也必须附加到电子邮件中。
At the link below you will find all details and a working code templatehttp://vba-useful.blogspot.fr/2014/01/send-html-email-with-embedded-images.html
在下面的链接中,您将找到所有详细信息和工作代码模板http://vba-useful.blogspot.fr/2014/01/send-html-email-with-embedded-images.html
回答by Karl-Henry Martinsson
As far as I know, you can only embed images in a rich text field using the Import method of the NotesUIDocument class, unless you want a much more complicated way.
据我所知,您只能使用 NotesUIDocument 类的 Import 方法在富文本字段中嵌入图像,除非您想要更复杂的方法。
The two ways I could see this being possible: * Use Midas LSX from GeniiSoft (commercial product) * Export the document as DXL, add the image (encoded as Base64) and then import the DXL back as a Notes document.
我认为这是可能的两种方式: * 使用 GeniiSoft(商业产品)中的 Midas LSX * 将文档导出为 DXL,添加图像(编码为 Base64),然后将 DXL 作为 Notes 文档重新导入。