Exchange Web服务 - 如何加载MIME内容类型PoEprty项目附件
-
26-12-2019 - |
题
我正在尝试运行以下代码的tghe来编写一个物品,该项目是磁盘上文件的电子邮件附件,但它会产生错误,因为它不会加载属性。
using (Stream FileToDisk = new FileStream(emailAttachmentsPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
itemAttachment.Load(
byte[] ContentBytes = System.Convert.FromBase64String(itemAttachment.ContentType);
FileToDisk.Write(ContentBytes, 0,ContentBytes.Length);
FileToDisk.Flush();
FileToDisk.Close();
}
.
我已经尝试过,但它不会编译:
email.Load(new PropertySet(ItemSchema.MimeContent));
.
如何获取项目内容类型,以便我可以创建我的ContentBytes
对象?
解决方案
最后我这样做了(基本上我需要加载 ietem 附件的mimi内容,加上一些额外的属性:
itemAttachment.Load(new PropertySet(BasePropertySet.FirstClassProperties));
itemAttachment.Load(new PropertySet(
BasePropertySet.IdOnly,
ItemSchema.Subject,
ItemSchema.DateTimeReceived,
ItemSchema.DisplayTo,
EmailMessageSchema.From, EmailMessageSchema.Sender,
EmailMessageSchema.HasAttachments, ItemSchema.MimeContent,
EmailMessageSchema.Body, EmailMessageSchema.Sender,
ItemSchema.Body) { RequestedBodyType = BodyType.Text });
string BodyText = itemAttachment.Item.Body.Text;
string itemAttachmentName = itemAttachment.Name.Replace(":", "");
// Put attachment contents into a stream.
emailAttachmentsPath = emailAttachmentsPath + "\\" + itemAttachmentName + ".eml";
var mimeContent = itemAttachment.Item.MimeContent;
//save to disk
using (var fileStream = new FileStream(emailAttachmentsPath, FileMode.Create))
{
fileStream.Write(mimeContent.Content, 0, mimeContent.Content.Length);
}
.
另一个选项:
var mimeContent2 = itemAttachment.Item.MimeContent;
byte[] ContentBytes = mimeContent2.Content;
//convert array of bytes into file
FileStream objfileStream = new FileStream("C:\\email2case\\temp\\testing" + System.DateTime.Now.ToString("HHmmss") + ".eml", FileMode.Create);
objfileStream.Write(ContentBytes, 0, ContentBytes.Length);
objfileStream.Close();
.
我希望这有助于某人!
其他提示
itemAttachment.Load(new PropertySet(EmailMessageSchema.MimeContent));
var mimeContent2 = itemAttachment.Item.MimeContent;
fileBytes = mimeContent2.Content;
. 不隶属于 StackOverflow