使用access vba将图像嵌入到邮件正文中

时间:2013-05-19 12:21:42

标签: vba ms-access access-vba lotus-notes

我目前正在使用以下代码通过附件发送来自访问的邮件。但我搜索到处都没有运气,以便将附件嵌入邮件正文本身。任何人都可以帮助我。

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

3 个答案:

答案 0 :(得分:1)

在正文字段中创建包含附件的电子邮件的好方法是使用MIME格式。

Set body = MailDoc.CreateMIMEEntity("Body") 
...

请查看http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/creating-a-mime-email-with-attachmenthttps://stackoverflow.com/a/2514633/2065611如何操作。

答案 1 :(得分:0)

据我所知,您只能使用NotesUIDocument类的Import方法在富文本字段中嵌入图像,除非您需要更复杂的方法。

我可以通过两种方式看到这种可能性: *使用GeniiSoft的Midas LSX(商业产品) *将文档导出为DXL,添加图像(编码为Base64),然后将DXL作为Notes文档导入。

答案 2 :(得分:0)

首先,您需要创建一个Outlook邮件对象,然后使用适当的&lt; img src ='myfile.jpg'&gt;编写邮件正文(以html格式)。标签。请注意以下几点:
     - 嵌入的图像必须保存在您的计算机上(作为jpg文件或png文件);
     - 自2013年展望以来,嵌入式图片也必须附加到电子邮件中。

在下面的链接中,您会找到所有详细信息和正常运行的代码模板 http://vba-useful.blogspot.fr/2014/01/send-html-email-with-embedded-images.html