C#、Lotus Interop:获取消息信息

发布于 2024-07-08 21:20:37 字数 624 浏览 11 评论 0原文

我正在使用 Interop.Domino.dll 从Lotus“数据库”(宽松使用的术语)。 我在检索某些字段时遇到一些困难,并且想知道如何正确执行此操作。 我一直在使用 NotesDocument.GetFirstItem 来检索主题、发件人和正文。

我在这方面的问题是:

  1. 如何检索回复地址? 有要去某个地方的“物品”清单吗? 我找不到它。
  2. 如何检索发件人和回复地址的友好名称?
  3. 当我以这种方式检索正文时,它的格式很奇怪,方括号集 ([]) 随机散布在邮件正文中,并且部分文本不是我期望的位置。

相关代码:

string 
  ActualSubject = nDoc.GetFirstItem("Subject").Text,
  ActualFrom = nDoc.GetFirstItem("From").Text,
  ActualBody = nDoc.GetFirstItem("Body").Text;

I'm using Interop.Domino.dll to retrieve E-mails from a Lotus "Database" (Term used loosely). I'm having some difficulty in retrieving certain fields and wonder how to do this properly. I've been using NotesDocument.GetFirstItem to retrieve Subject, From and Body.

My issues in this regard are thus:

  1. How do I retrieve Reply-To address? Is there a list of "Items" to get somewhere? I can't find it.
  2. How do I retrieve friendly names for From and Reply-To addresses?
  3. When I retrieve Body this way, it's formatted wierdly with square bracket sets ([]) interspersed randomly across the message body, and parts of the text aren't where I expect them.

Related code:

string 
  ActualSubject = nDoc.GetFirstItem("Subject").Text,
  ActualFrom = nDoc.GetFirstItem("From").Text,
  ActualBody = nDoc.GetFirstItem("Body").Text;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

稚气少女 2024-07-15 21:20:37

哈,明白了!

Object[] ni = (Object[])nDoc.Items;
string names_values = "";
for (int x = 0; x < ni.Length; x++)
{
NotesItem item = (NotesItem)ni[x];
if (!string.IsNullOrEmpty(item.Name)) names_values += x.ToString() + ": " + item.Name + "\t\t" + item.Text + "\r\n";
}

这返回了一个索引、名称和值的列表:

0: Received     from example.com ([192.168.0.1])          by host.example.com (Lotus Domino Release 6.5.4 HF182)          with ESMTP id 2008111917343129-205078 ;          Wed, 19 Nov 2008 17:34:31 -0500
1: Received     from example.com ([192.168.0.2])          by host2.example.com (Lotus Domino Release 6.5.4 HF182)          with ESMTP id 2008111917343129-205078 ;          Wed, 19 Nov 2008 17:34:31 -0500
2: X_PGRTRKID       130057945714t
3: X_PGRSRC     IE
4: ReplyTo      "example" <[email protected]>
5: Principal        "example" <[email protected]>
6: From         "IE130057945714t"<[email protected]>
7: SendTo       [email protected]
8: Subject      (Message subject redacted)
9: PostedDate       11/19/2008 03:34:15 PM
10: MIME_Version        1.0
11: $Mailer     SMTP DirectMail
12: $MIMETrack      Itemize by SMTP Server on xxxPT02-CORP/example(Release 6.5.4 HF182|May 31, 2005) at 11/19/2008 05:34:31 PM;Serialize by Router on xxxPT02-CORP/example(Release 6.5.4 HF182|May 31, 2005) at 11/19/2008 05:34:32 PM;Serialize complete at 11/19/2008 05:34:32 PM;MIME-CD by Router on xxxPT02-CORP/example(Release 6.5.4 HF182|May 31, 2005) at 11/19/2008 05:34:32 PM;MIME-CD complete at 11/19/2008 05:34:32 PM;Itemize by Router on camp-db-05/example(Release 7.0.2 HF76|November 03, 2006) at 11/19/2008 05:34:32 PM;MIME-CD by Notes Client on MyName/Guest/example(Release 6.5.6|March 06, 2007) at 11/20/2008 12:46:25 PM;MIME-CD complete at 11/20/2008 12:46:25 PM
13: Form        Memo
14: $UpdatedBy      ;CN=xxxPT02-CORP/O=example
15: $ExportHeadersConverted     1
16: $MessageID      <redacted@LocalDomain>
17: RouteServers        CN=xxxPT02-CORP/O=example;CN=camp-db-05/O=example
18: RouteTimes      11/19/2008 03:34:31 PM-11/19/2008 03:34:32 PM;11/19/2008 03:34:32 PM-11/19/2008 03:34:32 PM
19: $Orig       958F2E4E4B666AB585257506007C02A7
20: Categories      
21: $Revisions      
22: DeliveredDate       11/19/2008 03:34:32 PM
23: Body        []exampleexample

现在,谁能告诉我为什么 Body 总是变得混乱?

Hah, got it!

Object[] ni = (Object[])nDoc.Items;
string names_values = "";
for (int x = 0; x < ni.Length; x++)
{
NotesItem item = (NotesItem)ni[x];
if (!string.IsNullOrEmpty(item.Name)) names_values += x.ToString() + ": " + item.Name + "\t\t" + item.Text + "\r\n";
}

This returned a list of indices, names, and values:

0: Received     from example.com ([192.168.0.1])          by host.example.com (Lotus Domino Release 6.5.4 HF182)          with ESMTP id 2008111917343129-205078 ;          Wed, 19 Nov 2008 17:34:31 -0500
1: Received     from example.com ([192.168.0.2])          by host2.example.com (Lotus Domino Release 6.5.4 HF182)          with ESMTP id 2008111917343129-205078 ;          Wed, 19 Nov 2008 17:34:31 -0500
2: X_PGRTRKID       130057945714t
3: X_PGRSRC     IE
4: ReplyTo      "example" <[email protected]>
5: Principal        "example" <[email protected]>
6: From         "IE130057945714t"<[email protected]>
7: SendTo       [email protected]
8: Subject      (Message subject redacted)
9: PostedDate       11/19/2008 03:34:15 PM
10: MIME_Version        1.0
11: $Mailer     SMTP DirectMail
12: $MIMETrack      Itemize by SMTP Server on xxxPT02-CORP/example(Release 6.5.4 HF182|May 31, 2005) at 11/19/2008 05:34:31 PM;Serialize by Router on xxxPT02-CORP/example(Release 6.5.4 HF182|May 31, 2005) at 11/19/2008 05:34:32 PM;Serialize complete at 11/19/2008 05:34:32 PM;MIME-CD by Router on xxxPT02-CORP/example(Release 6.5.4 HF182|May 31, 2005) at 11/19/2008 05:34:32 PM;MIME-CD complete at 11/19/2008 05:34:32 PM;Itemize by Router on camp-db-05/example(Release 7.0.2 HF76|November 03, 2006) at 11/19/2008 05:34:32 PM;MIME-CD by Notes Client on MyName/Guest/example(Release 6.5.6|March 06, 2007) at 11/20/2008 12:46:25 PM;MIME-CD complete at 11/20/2008 12:46:25 PM
13: Form        Memo
14: $UpdatedBy      ;CN=xxxPT02-CORP/O=example
15: $ExportHeadersConverted     1
16: $MessageID      <redacted@LocalDomain>
17: RouteServers        CN=xxxPT02-CORP/O=example;CN=camp-db-05/O=example
18: RouteTimes      11/19/2008 03:34:31 PM-11/19/2008 03:34:32 PM;11/19/2008 03:34:32 PM-11/19/2008 03:34:32 PM
19: $Orig       958F2E4E4B666AB585257506007C02A7
20: Categories      
21: $Revisions      
22: DeliveredDate       11/19/2008 03:34:32 PM
23: Body        []exampleexample

Now, who can tell me why the Body keeps getting messed up?

萌能量女王 2024-07-15 21:20:37

Body 项是 NotesRichTextItem,而不是常规 NotesItem。 它们是 Lotus Notes 世界中不同类型的对象(并且常常是许多开发人员沮丧的根源!)

我在使用 COM 连接到 Domino 方面没有太多经验,并且我知道您可以访问的内容存在差异,但是 Domino Designer 帮助应该为您提供有关类的大量信息,例如 NotesRichTextItem。

也许“GetFormattedText”方法比访问项目的 Text 属性更适合您。

以下是该方法的示例(取自 Domino Designer 帮助)

Dim doc As NotesDocument
Dim rtitem As Variant
Dim plainText As String
Dim fileNum As Integer
'...set value of doc...
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
  plainText = rtitem.GetFormattedText( False, 0 )
End If
' get a file number for the file
fileNum = Freefile
' open the file for writing
Open "c:\plane.txt" For Output As fileNum
' write the formatted text to the file
Print #fileNum, plainText
' close the file
Close #fileNum

The Body item is a NotesRichTextItem, not a regular NotesItem. They are a different type of object in the Lotus Notes world (and often the source of much developer frustration!)

I don't have much experience with using COM to connect to Domino, and I know there are differences in what you have access to, but the Domino Designer Help should give you lots of information the classes, such as NotesRichTextItem.

Perhaps the method "GetFormattedText" would work better for you than accessing the item's Text property.

Here's an example of the method (taken from Domino Designer Help)

Dim doc As NotesDocument
Dim rtitem As Variant
Dim plainText As String
Dim fileNum As Integer
'...set value of doc...
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
  plainText = rtitem.GetFormattedText( False, 0 )
End If
' get a file number for the file
fileNum = Freefile
' open the file for writing
Open "c:\plane.txt" For Output As fileNum
' write the formatted text to the file
Print #fileNum, plainText
' close the file
Close #fileNum
思慕 2024-07-15 21:20:37

它可能无法工作,具体取决于您的环境设置方式,但在 domino 中处理邮件的最简单方法是将它们保留为 MIME,并通过 NotesMIMEEntity 和 NotesMIMEHeader 获取值。 仅当邮件来自 Web 而不是本机 Notes 并且环境已设置为以 MIME 格式存储邮件时,此功能才有效。

否则,您需要将正文作为 NotesRichTextItem 进行访问。 从该项目中,您需要获取一个 NotesRichTextNavigator,如果需要,它允许您在富文本结构中移动。

如果您认为结构应该相对简单,请尝试调用 NotesRichTextItem.GetFormattedText()。 如果这仍然不起作用,那么您将需要通过使用示例文档并查看 NotesRichTextNavigator 的结构来弄清楚发生了什么。

It may not work depending on how your environment is set up, but the easiest way to deal with mail in domino is to leave them as MIME and get at the values via the NotesMIMEEntity and NotesMIMEHeader. This will only work if the mail came in from the web rather than native Notes and the environment has been set up to store mail in MIME format.

Otherwise you need to access the body as a NotesRichTextItem. From that item you need to get a NotesRichTextNavigator that will allow you move around the rich text structure if you need to.

If you think the struture should be relatively simple try calling NotesRichTextItem.GetFormattedText(). If that still isn't working then you're going to need to work out what is happeing by playing with an example doument and seeing what the structure looks like to the NotesRichTextNavigator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文