通过 C# 应用程序接收电子邮件和下载附件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19449161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Receiving email and downloading attachment through a C# Application
提问by Himanshu Verma
I am trying to implement a WPF application which can receive the mails sent to a specific email address. The scenario is that, the user will send a PPT file as an attachment to a specific email address, and my WPF application will listen to this email and once it receives the email, it will download the attached file and saves it to the hard drive.
我正在尝试实现一个 WPF 应用程序,它可以接收发送到特定电子邮件地址的邮件。场景是,用户将 PPT 文件作为附件发送到特定的电子邮件地址,我的 WPF 应用程序将侦听此电子邮件,一旦收到电子邮件,它将下载附件并将其保存到硬盘驱动器.
I looked a bit, but all I found was that the System.Net.Mail
only supports sending emails through an application using System.Net.Mail.SmtpClient
class. Can anyone suggest me how to do this in WPF and C#.
我看了一点,但我发现System.Net.Mail
唯一支持通过使用System.Net.Mail.SmtpClient
类的应用程序发送电子邮件。谁能建议我如何在 WPF 和 C# 中做到这一点。
Thanks in advance!
提前致谢!
采纳答案by Krekkon
var client = new POPClient();
client.Connect("pop.gmail.com", 995, true);
client.Authenticate("[email protected]", "YourPasswordHere");
var count = client.GetMessageCount();
Message message = client.GetMessage(count);
Console.WriteLine(message.Headers.Subject);
A simple tip, that you can follow: http://www.joshwright.com/tips/sending-receiving-email-in-csharp
一个简单的提示,您可以遵循:http: //www.joshwright.com/tips/sending-receiving-email-in-csharp
回答by Libin TK
回答by Peter Huber
Since the various links in the other answers don't work anymore, here are 2 links to articles I wrote on CodeProject how to download emails received from POP3 servers like Gmail:
由于其他答案中的各种链接不再有效,这里有 2 个链接,指向我在 CodeProject 上写的如何下载从 Gmail 等 POP3 服务器收到的电子邮件:
POP3 Email Client
POP3 Email Client with full MIME Support
POP3 电子邮件客户
端 具有完整 MIME 支持的 POP3 电子邮件客户端
The code has been downloaded over 10000 times, but is too big to be posted here.
该代码已被下载超过 10000 次,但太大,无法在此处发布。