Search code examples
c#.netemailsmtp

Receiving email and downloading attachment through a C# Application


I am trying to implement an 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 - saving it to the hard drive.

I looked a bit, but all I found was the System.Net.Mail objects which only support sending emails through an application using the System.Net.Mail.SmtpClient class.

How can I do this in C#?


Solution

  • var client = new POPClient();
    client.Connect("pop.gmail.com", 995, true);
    client.Authenticate("admin@bendytree.com", "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/