Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving email and downloading attachment through a C# Application

Tags:

c#

.net

email

smtp

wpf

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.

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#.

Thanks in advance!

like image 659
Himanshu Verma Avatar asked Oct 18 '13 12:10

Himanshu Verma


People also ask

Why can't I download attachments?

Attachments won't open or download If attachments won't upload or download, try these steps in order: On your computer, check that you're using a supported browser. Try turning off extensions you have on your browser one at a time. Clear your browser's cache and cookies.

What app do I need to open email attachments?

1: Adobe Reader. In my opinion, Adobe Reader (Figure A) is the single most important app for opening email attachments. The vast majority of the important attachments I receive are in PDF format.


2 Answers

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: https://joshwright.com/tips/tips-sending-receiving-email-in-csharp/

like image 60
Krekkon Avatar answered Sep 21 '22 04:09

Krekkon


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:

POP3 Email Client
POP3 Email Client with full MIME Support

The code has been downloaded over 10000 times, but is too big to be posted here.

like image 31
Peter Huber Avatar answered Sep 23 '22 04:09

Peter Huber