How do I read incoming mail using C# [closed]
Asked Answered
P

3

6

I am looking for a solution to allow me to read incoming emails. The three methods I can think of to do this at the moment are:

  1. Create an Email Server parsing emails
  2. Hook into an existing exchange server
  3. Hook into outlook that is already set up with an email account

What is the best way to do this? And how does one go about implementing it?

Thanks

Phionna answered 6/1, 2011 at 12:21 Comment(2)
I think this really depends on what you are aiming to do with the email. If you are creating a web app then either polling, or using a service to receive incoming email will help. If you actually want to interact with the email from outlooks perspective then building an add-on can help.Pinfeather
@Steve I want to be able to read mail (with attachment), parse it, then send out an automated response.Phionna
D
9

If you are already dealing with an Exchange server as the mailbox host I would suggest leveraging that via IMAP (preferred) or POP access. Recently I developed a solution that accesses a specified mailbox via AfterLogic's MailBee.NET IMAP component which I think is worth the recommendation. They have a standard trial version and reasonable pricing. Also if you go this route either POP or IMAP automation is flexible enough to work with almost any mailbox server platform; It doesn't have to be limited to Exchange environments.

There are also free .NET IMAP components out there that may do the job as well. In my limited research I found that the free alternatives didn't quite meet all of my requirements or were not as easy to learn but your situation may differ. For completeness, here is a list of alternative / free IMAP libraries I considered before deciding to spend the money on MailBee:

To address the 2nd part of your question... The implementation in my recent project involved writing a very simple console application that references the MailBee.NET IMAP library. The console application has a standard config file and accepts command line arguments as parameters. We define Windows scheduled tasks to run the console application according to our process needs. I am sure you could do this any number of other ways but this was the simplest approach for our needs.

Doykos answered 6/1, 2011 at 12:27 Comment(2)
+1 for MailBee, we use it too.Bindle
Given comments above I'd say this answer is great although don't forget that there are ways out there to deliver the email directly without having to poll. You can setup a mail server to direct email as an HTTP request or use a third party service to do this too (I'm not going to mention any here because I run one but I'm sure you can find them)Pinfeather
P
5

I know this is an older thread but I wanted to add a link to a great open source Imap library called ImapX2: http://imapx.codeplex.com/

I tried most of the links in this thread to varying degrees of success but I found that the ImapX2 library work the best according to my needs.

Polypus answered 25/1, 2013 at 22:41 Comment(0)
R
2

Use existing IMAP server and IMAP component for that.

Creating your own IMAP server is a big security risk in my opinion.

There are free components, but most of them have problems with national characters and 'not standard' email messages...and there is none support (LumiSoft.Net is abandoned for almost 2 years)

using(Imap imap = new Imap())
{
    imap.Connect("imap.server.com");
    imap.Login("user", "password");

    imap.SelectInbox();
    List<long> uidList = imap.Search(Flag.Unseen);
    foreach (long uid in uidList)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));
        Console.WriteLine(email.Subject);
        Console.WriteLine(email.Attachments.Count);
    }
    imap.Close();
}

Mail.dll also includes SMTP component and template engine so you can send replies easily.

Disclaimer: I'm involved in the development of this commercial product.

Rothko answered 18/1, 2011 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.