POP3 in C# with System.Net.Pop3 #bizzehdee
If you want to have your c# application receive email on behalf of a user, then there are plenty of solutions out there, but the one I picked had no documentation, and I had to figure it out myself. Not too hard but, I thought I’d include it here to help people out.
I picked the NuGet package System.Net.Pop3 by bizzehdee because it was the first result in NuGet, but then realised it didn’t even have a “hello world” example.
// https://www.nuget.org/packages/System.Net.Pop3/ (bizzehdee)
var pop3Client = new Pop3Client();
pop3Client.Connect(“mail.server.com”, 110, false);
pop3Client.SendAuthUserPass(“postmaster@server.com”, “Password!”);
var intEmails = pop3Client.GetEmailCount();
var emails = new List<Pop3Message>();
for (uint i = 1; i <= intEmails; i++)
{
var email = pop3Client.GetEmail(i);
emails.Add(email);
}
This particular code was tested against a MailEnable email server installed on an Azure Virtual machine, with a catch-all email address. As a little “Gotcha” during setup, on azure, you have to open an endpoint on port 110 before it will accept pop3 connections, regardless of what the firewall on the machine itself says.