C# Fetch certain email with subject

83 Views Asked by At

How can I fetch an email, that has the subject I'm looking for in Hotmail using C#.

e.g. I want the emails(body/message) that has the word "Yahoo" in its subject.

Tried using many examples online but they weren't really clear. Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

You can connect to your hotmail account using the OpenPop.Net open source library. It has a lot of useful methods to communicate with a POP3 server. There is a lot of useful examples online. A simple code to connect to the POP3 server could work look this:

using(Pop3Client client = new Pop3Client())
{
    client.Connect(hotmailHostName, pop3Port, useSsl);
    client.Authenticate(username, password, AuthenticationMethod.UsernameAndPassword);

    // And here you can use the client.GetMessage() method to get a desired message. 
    // You can iterate all the messages and check properties on each of them. 
}

The hotmailHostName should be "pop3.live.com".
The pop3Port should be 995.
The useSsl should be true.