从Excel VBA发送格式化的Lotus Notes富文本电子邮件 [英] Sending formatted Lotus Notes rich text email from Excel VBA

查看:325
本文介绍了从Excel VBA发送格式化的Lotus Notes富文本电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很少有Lotus Script或Notes / Domino知识,但是我有一个程序,从很久以前的某个地方复制过来,允许我通过VBA通过Notes发送电子邮件。我通常只会将内部通知用于格式化并不重要的内部通知。



我现在想使用这种方式将外部电子邮件发送给客户端,公司类型将相反,电子邮件符合我们的风格指南(基本上是无衬线字体)。



我正在告诉他们,代码只适用于纯文本,但随后我注意到该例程确实引用了某种类型的CREATERICHTEXTITEM对象。这是否意味着我可以在已经传递到邮件例程之后将身体文本字符串应用某种格式化?除了坚持我们珍贵的品牌价值观,对于我强调电子邮件中的某些段落来说,这将是非常有用的。



我已经挖掘了看看这个代码是否可以适应,但是不熟悉Notes的对象模型,以及在线Notes资源似乎反映了应用程序本身的直观性,这意味着我没有得到很多。



代码:

 Sub sendEmail(EmailSubject As String,EMailSendTo As String,EMailBody As String,MailServer as String)

Dim objNotesSession As Object
Dim objNotesMailFile As Object
Dim objNotesDocument As Object
Dim objNotesField As Object
Dim sendmail As Boolean

'added用于集成到报告工具
Dim dbString As String

dbString =mail\&Application.UserName&.nsf

错误GoTo SendMailError
'建立与Notes的连接
设置objNo tesSession = CreateObject(Notes.NotesSession)
错误恢复下一步
'建立与邮件文件的连接
设置objNotesMailFile = objNotesSession.GETDATABASE(MailServer,dbString)
'打开邮件
objNotesMailFile.OPENMAIL
错误GoTo 0

'创建新的备忘录
设置objNotesDocument = objNotesMailFile.createdocument

Dim oWorkSpace As Object, oUIdoc As Object
设置oWorkSpace = CreateObject(Notes.NotesUIWorkspace)
设置oUIdoc = oWorkSpace.CurrentDocument

'创建'主题字段'
设置objNotesField = objNotesDocument .APPENDITEMVALUE(Subject,EmailSubject)

'创建'发送到'字段
设置objNotesField = objNotesDocument.APPENDITEMVALUE(SendTo,EMailSendTo)

'创建'复制到'字段
设置objNotesField = objNotesDocument.APPENDITEMVALUE(CopyTo,EMailCCTo)

'创建'盲目复制到'字段
设置objNotesField = objNotesDocument.APPENDITEMVALUE(BlindCopyTo,EMailBCCTo)

'创建Body的备忘录
设置objNotesField = objNotesDocument.CREATERICHTEXTITEM(Body)

带objNotesField
.APPENDTEXT emailBody
.ADDNEWLINE 1
结束

'发送电子邮件

调用objNotesDocument.Save( True,False,False)
objNotesDocument.SaveMessageOnSend = True
'objNotesDocument.Save
objNotesDocument.Send(0)

'发布存储
设置objNotesSession = Nothing
设置objNotesMailFile = Nothing
设置objNotesDocument = Nothing
设置objNotesField =无

'设置返回码
sendmail = True

退出Sub

SendMailError:
Dim Msg
Msg =Error#&Str(Err.Number)&由...生成_
& Err.Source&Chr(13)&Err.Description
MsgBox Msg,,呃ror,Err.HelpFile,Err.HelpContext
sendmail = False
End Sub


解决方案

简短的答案是是的。长的答案是痛苦的。在Notes中没有任何好的类暴露于操纵富文本项。然而,您可以研究的几个是NotesRichTextStyle,NotesRichTextParagraphStyle和NotesRichTextTable等等。这些类可帮助您定义一些富文本元素,并将其以编程方式添加到富文本字段。



另一种方法,因为您发送电子邮件,是使用NotesMIMEEntity类并使用HTML构建电子邮件(方式更简单)。以下是一些示例代码:

  Set s = New NotesSession 
Dim docMail As NotesDocument
Dim body As NotesMIMEEntity
Dim stream As NotesStream

设置db = s.CurrentDatabase
s.ConvertMIME = False'不要将MIME转换为富文本

'创建电子邮件要发送
设置docMail = db.CreateDocument

使用docMail
.SendTo =发送到地址
.From = FROM ADDRESS
.Principal = FROM ADDRESS
.ReplyTo = REPLY to ADDRESS
.Subject = SUBJECT
.Form =Memo
End with

设置stream = s.CreateStream
设置body = docMail.CreateMIMEEntity
调用stream.WriteText(你的HTML代码到这里)

'ENC_IDENTITY_8BIT由于在notes.net上找到了technote
' http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/aeedaf28e47546ad85256f6a000a4b48?OpenDocument
调用body.SetContentFromText(stream,text / html ; charset = iso-8859-1,ENC_IDENTITY_8BIT)

调用docMail.Send(False)
设置docMail = Nothing
设置body = Nothing
设置stream =没有

s.ConvertMIME = True'恢复转换

本质上你会需要在NotesSession中关闭ConvertMIME设置。然后创建一个新文档,设置邮件属性等。该部分已经在您的VBA代码中。接下来,创建MIMEEntity和一个流来保存HTML文本。最后在您的MIMEEntity对象上调用SetContentFromText方法。然后发送你的电子邮件请注意,最后一次通话是为NotesSession重新打开ConvertMIME功能。



我不知道这是否可以通过COM工作,但它在Notes中的LotusScript代理中可以正常工作。



我希望这有帮助!


I have little Lotus Script or Notes/Domino knowledge but I have a procedure, copied from somewhere a long time ago, that allows me to email through Notes from VBA. I normally only use this for internal notifications where the formatting hasn't really mattered.

I now want to use this to send external emails to a client, and corporate types would rather the email complied with our style guide (a sans-serif typeface basically).

I was about to tell them that the code only works with plain text, but then I noticed that the routine does reference some sort of CREATERICHTEXTITEM object. Does this mean I could apply some sort of formatting to the body text string after it has been passed to the mail routine? As well as upholding our precious brand values, this would be quite handy to me for highlighting certain passages in the email.

I've had a dig about the 'net to see if this code could be adapted, but being unfamiliar with Notes' object model, and the fact that online Notes resources seem to mirror the application's own obtuseness, meant I didn't get very far.

The code:

Sub sendEmail(EmailSubject As String, EMailSendTo As String, EMailBody As String, MailServer as String)

    Dim objNotesSession As Object
    Dim objNotesMailFile As Object
    Dim objNotesDocument As Object
    Dim objNotesField As Object
    Dim sendmail As Boolean

    'added for integration into reporting tool
    Dim dbString As String

    dbString = "mail\" & Application.UserName & ".nsf"

On Error GoTo SendMailError
    'Establish Connection to Notes
    Set objNotesSession = CreateObject("Notes.NotesSession")
On Error Resume Next
    'Establish Connection to Mail File
    Set objNotesMailFile = objNotesSession.GETDATABASE(MailServer, dbString)
    'Open Mail
    objNotesMailFile.OPENMAIL
On Error GoTo 0

    'Create New Memo
    Set objNotesDocument = objNotesMailFile.createdocument

    Dim oWorkSpace As Object, oUIdoc As Object
    Set oWorkSpace = CreateObject("Notes.NotesUIWorkspace")
    Set oUIdoc = oWorkSpace.CurrentDocument

    'Create 'Subject Field'
    Set objNotesField = objNotesDocument.APPENDITEMVALUE("Subject", EmailSubject)

    'Create 'Send To' Field
    Set objNotesField = objNotesDocument.APPENDITEMVALUE("SendTo", EMailSendTo)

    'Create 'Copy To' Field
    Set objNotesField = objNotesDocument.APPENDITEMVALUE("CopyTo", EMailCCTo)

    'Create 'Blind Copy To' Field
    Set objNotesField = objNotesDocument.APPENDITEMVALUE("BlindCopyTo", EMailBCCTo)

    'Create 'Body' of memo
    Set objNotesField = objNotesDocument.CREATERICHTEXTITEM("Body")

    With objNotesField
        .APPENDTEXT emailBody
        .ADDNEWLINE 1
    End With

    'Send the e-mail

    Call objNotesDocument.Save(True, False, False)
    objNotesDocument.SaveMessageOnSend = True
    'objNotesDocument.Save
    objNotesDocument.Send (0)

    'Release storage
    Set objNotesSession = Nothing
    Set objNotesMailFile = Nothing
    Set objNotesDocument = Nothing
    Set objNotesField = Nothing

    'Set return code
    sendmail = True

    Exit Sub

SendMailError:
    Dim Msg
    Msg = "Error # " & Str(Err.Number) & " was generated by " _
                & Err.Source & Chr(13) & Err.Description
    MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
    sendmail = False
End Sub

解决方案

The short answer is Yes. The long answer is painful. There aren't any great classes exposed to manipulate rich text items in Notes. However a few that you can research are the NotesRichTextStyle, NotesRichTextParagraphStyle, and NotesRichTextTable to name a few. These classes help you define some rich text elements and add them programmatically to your rich text field.

Another approach, since you're sending email, is to use the NotesMIMEEntity classes and build the email using HTML (way way easier). Here's some sample code:

Set s = New NotesSession
Dim docMail As NotesDocument
Dim body As NotesMIMEEntity
Dim stream As NotesStream

Set db = s.CurrentDatabase
s.ConvertMIME = False ' Do not convert MIME to rich text

'Create email to be sent
Set docMail = db.CreateDocument

With docMail
        .SendTo = SEND TO ADDRESS
        .From = FROM ADDRESS
        .Principal = FROM ADDRESS
        .ReplyTo = REPLY TO ADDRESS
        .Subject = SUBJECT
        .Form = "Memo"
End With

  Set stream = s.CreateStream
Set body = docMail.CreateMIMEEntity
Call stream.WriteText ("YOUR HTML CODE GOES HERE")

'ENC_IDENTITY_8BIT used because of technote found on notes.net
'http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/aeedaf28e47546ad85256f6a000a4b48?OpenDocument
Call body.SetContentFromText (stream, "text/html;charset=iso-8859-1",ENC_IDENTITY_8BIT) 

Call docMail.Send(False)
Set docMail = Nothing
Set body = Nothing
Set stream = Nothing

s.ConvertMIME = True ' Restore conversion   

Essentially you'll need to turn the ConvertMIME setting off in the NotesSession. Then create a new document, set the mail properties, etc. That part is already in your VBA code. Next, create the MIMEEntity and a stream to hold your HTML text. Finally call the SetContentFromText method on your MIMEEntity object. Then send your email. Note the last call is to turn the ConvertMIME feature back on for the NotesSession.

I'm not sure if this will all work via COM, but it does work well in LotusScript agents in Notes.

I hope this helps!

这篇关于从Excel VBA发送格式化的Lotus Notes富文本电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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