我必须检索发送的电子邮件的正文,并将其存储在共享文件夹中。我有以下代码示例来从电子邮件中检索附件并存储它。
EmailMessage message = EmailMessage.Bind(service, new ItemId(item.Id.ToString()),
new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
foreach (Attachment attachment in message.Attachments)
{
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
// Load attachment contents into a file.
fileAttachment.Load("C:\\CodeCopy\\Email\\temp\\" + fileAttachment.Name);类似地,如果我想使用EmailMessage.body属性,我该如何使用它。我是一个初学者,所以请给我一个详细的回答。
发布于 2011-01-31 19:08:23
可以使用EmailMessage.Body属性获取表示消息正文的对象,然后调用其ToString()方法以字符串形式获取正文内容,并将该字符串写入文件:
using System.IO;
using System.Text;
using Microsoft.Exchange.WebServices.Data;
EmailMessage message = EmailMessage.Bind(service, new ItemId(item.Id.ToString()),
new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
using (StreamWriter writer = new StreamWriter(String.Format(
CultureInfo.InvariantCulture, @"C:\CodeCopy\Email\temp\{0}.body.txt",
item.Id.ToString().Replace('\\', '_')))) {
writer.Write(message.Body.ToString());
}https://stackoverflow.com/questions/4849642
复制相似问题