Exchange-Webdienste – So laden Sie den Mime-Inhaltstyp eines Elementanhangs
-
26-12-2019 - |
Frage
Ich versuche, den folgenden Code auszuführen, um ein Element zu schreiben, bei dem es sich um einen E-Mail-Anhang einer Datei auf der Festplatte handelt, es wird jedoch eine Fehlermeldung angezeigt, da die Eigenschaft nicht geladen ist.
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();
}
Ich habe Folgendes versucht, aber es lässt sich nicht kompilieren:
email.Load(new PropertySet(ItemSchema.MimeContent));
Wie kann ich den Inhaltstyp des Elements erhalten, damit ich meinen erstellen kann? ContentBytes
Objekt?
Lösung
Am Ende habe ich das gemacht (im Grunde musste ich den Mimi-Inhalt laden ietem Anhang, plus einige zusätzliche Eigenschaften:
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);
}
andere Option:
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();
Ich hoffe, das hilft jemandem!
Andere Tipps
itemAttachment.Load(new PropertySet(EmailMessageSchema.MimeContent));
var mimeContent2 = itemAttachment.Item.MimeContent;
fileBytes = mimeContent2.Content;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow