【发布时间】:2011-05-24 20:12:59
【问题描述】:
我正在尝试从电子邮件的附件中获取内容。我能够阅读电子邮件及其所有属性。附件是一个文本文件 (.txt)。我将如何获取附件的实际文本内容?下面是我的代码的一部分,展示了我如何抓取每封电子邮件,然后获取其属性并将它们存储在 findResults 列表中。像 fileAttachment.Name 这样的东西会给我附件的名称。 fileAttachment.content.tostring() 只会显示 system.Byte[].
FindItemsResults<Item> findResults = service.FindItems(fid1, new ItemView(int.MaxValue));
service.LoadPropertiesForItems(from Item item in findResults select item, PropertySet.FirstClassProperties);
foreach (Item item in findResults)
{
String body = "";
#region attachments
if (ReadAttachments == "1")
{
EmailMessage message = EmailMessage.Bind(service, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
foreach (Attachment attachment in message.Attachments)
{
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
// Load the file attachment into memory and print out its file name.
fileAttachment.Load();
String attachbody = fileAttachment.Content.ToString();
if (attachbody.Length > 8000)
{
attachbody = attachbody.Substring(0, 8000);
}
Console.writeline(attachbody);
#endregion
}
}
}
#endregion
}
【问题讨论】:
标签: c# email exchange-server attachment exchangewebservices