如何下载电子邮件附件文件并保存 [英] how to download email attachment file and save
问题描述
如何下载电子邮件附件并保存在本地驱动器中
how to download email attachment and save in local drive
推荐答案
using System.Net.Mail;
using Lesnikowski.Client;
using Lesnikowski.Client.IMAP;
using Lesnikowski.Mail;
using Lesnikowski.Mail.Fluent;
using Lesnikowski.Mail.Headers;
using Lesnikowski.Mail.Headers.Constants;
使用(Imap imap = new Imap())
{
imap.Connect("smtp.ascent-group.com");
imap.Login("software@ascent-group.com","ascent44");
imap.SelectInbox();
列出< long> uids = imap.SearchFlag(Flag.All);
如果(uids.Count< 1)
{
MessageBox.Show("MailBox为空");
}
其他
{
foreach(uid中的长uid)
{
字符串eml = imap.GetMessageByUID(uid);
IMail电子邮件=新的MailBuilder()
.CreateFromEml(eml);
//Console.WriteLine(email.Subject);
//将所有附件保存到磁盘
email.Attachments.ForEach(mime => mime.Save("d:/" + mime.SafeFileName));
//email.Date.ToString();
imap.DeleteMessageByUID(uid);
}
imap.Close();
MessageBox.Show(附件已成功下载....");
}
}
using (Imap imap = new Imap())
{
imap.Connect("smtp.ascent-group.com");
imap.Login("software@ascent-group.com", "ascent44");
imap.SelectInbox();
List<long> uids = imap.SearchFlag(Flag.All);
if (uids.Count < 1)
{
MessageBox.Show("MailBox is empty");
}
else
{
foreach (long uid in uids)
{
string eml = imap.GetMessageByUID(uid);
IMail email = new MailBuilder()
.CreateFromEml(eml);
//Console.WriteLine(email.Subject);
// save all attachments to disk
email.Attachments.ForEach(mime => mime.Save("d:/" + mime.SafeFileName));
//email.Date.ToString();
imap.DeleteMessageByUID(uid);
}
imap.Close();
MessageBox.Show("Attachment downloaded successfully....");
}
}
右键单击,然后选择另存为...
:)
Right click, and select Save As...
:)
这篇关于如何下载电子邮件附件文件并保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!