如何将电子邮件附件保存到本地硬盘 [英] How to save email attachments to local hard disk

查看:731
本文介绍了如何将电子邮件附件保存到本地硬盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将电子邮件附件以实际格式保存到C#中的本地硬盘中

How to save email attachments to local hard disk in C# with actual format

推荐答案

anjutlya,

请参考这可能对您有帮助 http: //stackstackflow.com/questions/2040321/how-to-save-email-attachments-to-local-hard-disk-in-c [ ^ ]
Hi anjutlya,

Please refer this might be helpful to you http://stackoverflow.com/questions/2040321/how-to-save-email-attachments-to-local-hard-disk-in-c[^]


使用System.Net.Mail;
使用Lesnikowski.Client;
使用Lesnikowski.Client.IMAP;
使用Lesnikowski.Mail;
使用Lesnikowski.Mail.Fluent;
使用Lesnikowski.Mail.Headers;
使用Lesnikowski.Mail.Headers.Constants;



使用(Imap imap = new Imap())
{
imap.Connect("pop3服务器");
imap.Login("loginid","password");

imap.SelectInbox();
列出uid = 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 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;



using (Imap imap = new Imap())
{
imap.Connect("pop3 server");
imap.Login("loginid", "password");

imap.SelectInbox();
List 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....");
}
}


在CodeProject中搜索电子邮件附件",其中有很多文章.
Search CodeProject for "email attachment" and there are a lot of articles for this.


这篇关于如何将电子邮件附件保存到本地硬盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆