在 Excel 中创建富文本电子邮件,通过 Lotus Notes 7 动态创建的 RTF 发送
我正在尝试在 Lotus Notes 7 客户端中以编程方式生成一封电子邮件,其内容是我专门为每封要发送的电子邮件构建的 RTF 代码块(在 Excel 中)。
我能够构建、填充和发送电子邮件。但正文看起来像是我的 RTF 代码的 ascii 文本,而不是我期望的格式化版本。
我有一种感觉,这是因为我的电子邮件程序功能(继承自以前的开发人员)将其作为纯文本传递。我怎样才能让它以富文本形式传递?
相关电子邮件代码:(邮箱名称是公司特定的,因此已更改) 另外,请注意,我希望 RichText 作为正文,而不是附件。
Public Sub SendNotesMail(sSubject, sTo, sCC, sBCC, sAttachment, sMessage, Optional sSaveSent As Boolean = True)
'Set up the objects required for Automation into lotus notes
Dim Maildb 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc 'The mail document itself
Dim RichTextitem As Object 'The RichText Item
Dim AttachME 'The sAttachment richtextfile object
Dim Session 'The notes session
Dim EmbedObj 'The embedded object (sAttachment)
Dim rAttach() As String
Dim x As Integer
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
Session.ConvertMime = False
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = "XXXXX.nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", "XXXXXX.nsf")
' Is Mail file already open?
If Maildb.IsOpen = False Then
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.form = "Memo"
MailDoc.sendto = sTo
MailDoc.CopyTo = sCC
MailDoc.BlindCopyTo = sBCC
MailDoc.Subject = sSubject
Set RichTextitem = MailDoc.Createrichtextitem("Body")
Call RichTextitem.appendtext(sMessage)
MailDoc.SaveMessageOnSend = sSaveSent
'Set up the embedded object and Attachment and attach it
If sAttachment <> "" Then
ParseWords rAttach(), sAttachment, ";"
For x = 0 To UBound(rAttach) Step 1
Set AttachME = MailDoc.Createrichtextitem("Attachment")
Set EmbedObj = AttachME.EmbedObject(1454, "", rAttach(x), "Attachment")
Next x
End If
'Send the document
MailDoc.SaveMessageOnSend = True
MailDoc.SEND 0, sTo
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
这是我的 RTF 文本的一大块。它不渲染任何内容,这只是为了显示我的意思的文本格式。
{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi31507\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f1\fbidi \fswiss\fcharset0\fprq2{\*\panose 020b0604020202020204}Arial;}
{\f34\fbidi \froman\fcharset1\fprq2{\*\panose 02040503050406030204}Cambria Math;} {\flomajor\f31500\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbmajor\f31501\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhimajor\f31502\fbidi \froman\fcharset0\fprq2{\*\panose 02040503050406030204}Cambria;}
{\fbimajor\f31503\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\flominor\f31504\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbminor\f31505\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhiminor\f31506\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}
{\fbiminor\f31507\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f39\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\f40\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}
{\f42\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\f43\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\f44\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f45\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}
{\f46\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\f47\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f49\fbidi \fswiss\fcharset238\fprq2 Arial CE;}{\f50\fbidi \fswiss\fcharset204\fprq2 Arial Cyr;}
{\f52\fbidi \fswiss\fcharset161\fprq2 Arial Greek;}{\f53\fbidi \fswiss\fcharset162\fprq2 Arial Tur;}{\f54\fbidi \fswiss\fcharset177\fprq2 Arial (Hebrew);}{\f55\fbidi \fswiss\fcharset178\fprq2 Arial (Arabic);}
I'm trying to programatically generate an email in my Lotus Notes 7 client, with the contents being a chunk of RTF code that I build specifically for each email to be sent, in excel.
I'm able to build, populate and send the email. But the body comes across as the ascii text of my RTF code, rather than the formatted version I was expecting.
I have a feeling it's because my emailer function (inherited from a previous developer) is passing it as plain text. How can I get it passed as Rich text?
The relevant emailer code: (mail box name is company specific, so has been changed)
Also, please note that I want the RichText as the body, not an attachment.
Public Sub SendNotesMail(sSubject, sTo, sCC, sBCC, sAttachment, sMessage, Optional sSaveSent As Boolean = True)
'Set up the objects required for Automation into lotus notes
Dim Maildb 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc 'The mail document itself
Dim RichTextitem As Object 'The RichText Item
Dim AttachME 'The sAttachment richtextfile object
Dim Session 'The notes session
Dim EmbedObj 'The embedded object (sAttachment)
Dim rAttach() As String
Dim x As Integer
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
Session.ConvertMime = False
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = "XXXXX.nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", "XXXXXX.nsf")
' Is Mail file already open?
If Maildb.IsOpen = False Then
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.form = "Memo"
MailDoc.sendto = sTo
MailDoc.CopyTo = sCC
MailDoc.BlindCopyTo = sBCC
MailDoc.Subject = sSubject
Set RichTextitem = MailDoc.Createrichtextitem("Body")
Call RichTextitem.appendtext(sMessage)
MailDoc.SaveMessageOnSend = sSaveSent
'Set up the embedded object and Attachment and attach it
If sAttachment <> "" Then
ParseWords rAttach(), sAttachment, ";"
For x = 0 To UBound(rAttach) Step 1
Set AttachME = MailDoc.Createrichtextitem("Attachment")
Set EmbedObj = AttachME.EmbedObject(1454, "", rAttach(x), "Attachment")
Next x
End If
'Send the document
MailDoc.SaveMessageOnSend = True
MailDoc.SEND 0, sTo
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
Here is a chunk of my RTF text. It doesn't render anything, this is just to show the text format I mean.
{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch31505\stshfloch31506\stshfhich31506\stshfbi31507\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f1\fbidi \fswiss\fcharset0\fprq2{\*\panose 020b0604020202020204}Arial;}
{\f34\fbidi \froman\fcharset1\fprq2{\*\panose 02040503050406030204}Cambria Math;} {\flomajor\f31500\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbmajor\f31501\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhimajor\f31502\fbidi \froman\fcharset0\fprq2{\*\panose 02040503050406030204}Cambria;}
{\fbimajor\f31503\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\flominor\f31504\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbminor\f31505\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhiminor\f31506\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}
{\fbiminor\f31507\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f39\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\f40\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}
{\f42\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\f43\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\f44\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f45\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}
{\f46\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\f47\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f49\fbidi \fswiss\fcharset238\fprq2 Arial CE;}{\f50\fbidi \fswiss\fcharset204\fprq2 Arial Cyr;}
{\f52\fbidi \fswiss\fcharset161\fprq2 Arial Greek;}{\f53\fbidi \fswiss\fcharset162\fprq2 Arial Tur;}{\f54\fbidi \fswiss\fcharset177\fprq2 Arial (Hebrew);}{\f55\fbidi \fswiss\fcharset178\fprq2 Arial (Arabic);}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将需要实际使用 Richtext 字段的本机 Lotus Notes 方法,并从您创建的“RichtextItem”对象创建 Richtext 内容。 sMessage 字段需要是纯文本,如果需要,则需要通过 NotesRichTextStyle 对象指定格式。
找到 R7 的 API 详细信息 此处 和 此处。当编写“样式化”富文本时,您需要内联执行,也就是说,开始附加文本,然后在将其设为粗体之前,获取一个notesRichTextStyle对象,在其上设置属性,然后将其应用到富文本对象,然后编写文本。当您需要再次更改样式时,请重复此过程。这个示例演示了用法。 MIDAS Richtext 是一款久经考验的真实产品,它消除了创建 Richtext 过程中的麻烦,但您需要购买 许可证。
对于附件,您可以使用 RichTextItem 的“embedObject”方法将文件附加到电子邮件正文中,正如您在代码示例中所示的那样,但我认为您可以将 richtextitem 对象重新用于“ body”字段,不要使用“attachment”字段。您应该能够通过互联网发送电子邮件,并且用户可以看到电子邮件中附件的位置并将其分离。
这里是嵌入对象的帮助文档和示例,以防您还不知道它的功能。 (提供的所有链接均适用于 R7。)
You will need to actually use native Lotus Notes methods for a richtext field and create the richtext content from the "RichtextItem" object you have created. The sMessage field will need to be plain text, and if you will then need to specify the formatting via the NotesRichTextStyle object.
API details for R7 found here and here. When writing "styled" richtext you need to do it inline, that is, you start appending text, then before you want to make it bold, get a notesRichTextStyle object set the properties on it, then apply it to the richtext object, then write the text. When you need to change styles again, you repeat this process. This example demonstrates the usage. MIDAS richtext is a tried and true product that takes the hassle out of the process for creating richtext, but you will need to purchase a license.
For the attachment, you can use the "embedObject" method of the RichTextItem to attach a file into the body of the email, as you have already shown in your code sample, but I think you can re-use the richtextitem object for the "body" field, don't use the "attachment" field. You should be able to send the email over the internet and users see the attachment's location in the email and detach it.
Here is the help documentation for embedding objects with examples in case you're weren't already aware of it's functionality. (All the links provided are for R7.)
RTF 格式的文本无法与 Lotus Notes 的 Rich Text 格式配合使用。它们是不同的东西。
您可以使用 Notes API 创建富文本。请参阅以 NotesRichTextXXXX 开头的方法。请注意,这并不简单,而且不幸的是,没有简单的方法将 RTF 转换为 Notes Rich Text。
有一个附加组件可以帮助您处理富文本。我还没有尝试过,但一直强烈推荐它: http://www.geniisoft.com /showcase.nsf/MidasLSX
使用 MIME 类,您可以通过 Notes 发送 HTML 电子邮件,这可能是您最好的选择。
Your RTF formatted text won't work with Lotus Notes's Rich Text format. They are separate things.
You can create Rich Text using the Notes API. See the methods that start with NotesRichTextXXXX. It's not simple, mind you, and there's no easy way to convert the RTF to Notes Rich Text unfortunately.
There is an add-on that will help you deal with Rich Text. I haven't tried it but it has always been highly recommended: http://www.geniisoft.com/showcase.nsf/MidasLSX
Using the MIME classes you can send an HTML email via Notes, and that may be your best bet.