I've been asked to write a Windows service in C# to periodically monitor an email inbox and insert the details of any messages received into a database table.
My instinct is to do this via POP3 and sure enough, Googling for ".NET POP3 component" produces countless (ok, 146,000) results.
Has anybody done anything similar before and can you recommend a decent component that won't break the bank (a few hundred dollars maximum)?
Would there be any benefits to using IMAP rather than POP3?
For sending email we need a SMTP Server, so in ASP.Net we have the SmtpClient class, using that class object we set its properties for the SMTP settings. SmtpClient client = newSmtpClient("smtp.gmail.com", 587);
Sending an email using SMTP. The standard approach to send an email using C# is SMTP (Simple Mail Transfer Protocol). It is a network protocol used to send emails over the internet.
With IMAP protocol you can access sub folders, and set message status (seen/unseen), also you can use IDLE feature for instant notifications.
Mail.dll includes POP3, IMAP, SMTP components with SSL support and powerful MIME parser:
using(Imap imap = new Imap())
{
imap.Connect("imap.server.com"); // or ConnectSSL for SSL
imap.Login("user", "password");
imap.SelectInbox();
List<long> uids = imap.Search(Flag.Unseen);
foreach (long uid in uids)
{
IMail mail = new MailBuilder()
.CreateFromEml(imap.GetMessageByUID(uid));
Console.WriteLine(mail.Subject);
}
imap.Close();
}
Please note that this is commercial product that I've created.
You can download it at https://www.limilabs.com/mail
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With