MailKit kitaplığını nasıl kullanacağımı öğrenmeye çalışıyorum ama ekleri almaya çalışıyorum. Şimdiye kadar, kodum bir posta kutusu açacak, her bir iletiden geçecek ve gönderen, konu, gövde, tarih vb. Gibi verileri depolayacaktır ancak eklerle ilgilenemiyorum.MailKit kitaplığını kullanarak ekleri kaydetme?
Burada bulunan diğer insanların çözümlerini github ve diğer siteler üzerinde kullanmaya çalıştım ama hala kodlarında ne yaptıklarını tam olarak anlamadım ve bir çözüm bulmak için yaklaştığımda daha fazla hataya neden oluyor Bu yüzden tüm kodları vurgulayıp sildim. Tembel görünmek istemem ama birisinin bunu nasıl başarabileceğimi açıklayabilmesini isterdim. Temel olarak bir web formu uygulaması için bir posta istemcisi oluşturmaya çalışıyorum. Aşağıda
Gördüğünüz gibi ben oldukça clueless değilim :) // Open the Inbox folder
client.Inbox.Open(FolderAccess.ReadOnly, cancel.Token);
//get the full summary information to retrieve all details
var summary = client.Inbox.Fetch(0, -1, MessageSummaryItems.Full, cancel.Token);
foreach (var msg in summary)
{
//this code originally downloaded just the text from the body
var text = msg.Body as BodyPartText;
//but I tried altering it so that it will get attachments here also
var attachments = msg.Body as BodyPartBasic;
if (text == null)
{
var multipart = msg.Body as BodyPartMultipart;
if (multipart != null)
{
text = multipart.BodyParts.OfType<BodyPartText>().FirstOrDefault();
}
}
if (text == null)
continue;
//I hoped this would get the messages where the content dispositon was not null
//and let me do something like save the attachments somewhere but instead it throws exceptions
//about the object reference not set to an instance of the object so it's very wrong
if (attachments.ContentDisposition != null && attachments.ContentDisposition.IsAttachment)
{
//I tried to do the same as I did with the text here and grab the body part....... but no
var attachedpart = client.Inbox.GetBodyPart(msg.Index, attachments, cancel.Token);
}
else
{
//there is no plan b :(
}
// this will download *just* the text
var part = client.Inbox.GetBodyPart(msg.Index, text, cancel.Token);
//cast main body text to Text Part
TextPart _body = (TextPart)part;
Tam olarak ne yapmak istersiniz? Ekleri indirmek ve diske (veya bir yere) kaydetmek mi istiyorsunuz? Ana gövde metni ne olacak? – jstedfast