Automated processing of an Email in C#

北城余情 提交于 2019-12-08 06:09:08

问题


Similar question as this one but for a Microsoft Environment.

Email --> Exchange Server -->[something]

For the [something] I was using Outlook 2003 & C# but it feels messy (A program is trying to access outlook, this could be a virus etc)

Microsoft.Office.Interop.Outlook.Application objOutlook = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace objNS = objOutlook.GetNamespace("MAPI");
objNS.Logon("MAPIProfile", "MAPIPassword", false, true);

Is this the best way to do it? Is there a better way of retrieving and processing emails in a Microsoft environment???


回答1:


This library provides you basic support for the POP3 protocol and MIME, you can use it to check specified mailboxes and retrieve emails and attachments, you can tweak it to your needs.

Here is another library, this one is for the IMAP protocol, it's very basic but also allows you to fetch complete messages, including attachments...




回答2:


I've been happy with the Rebex components which provide IMAP access. Of course you need to ensure your Exchange administrators will open an IMAP port on your Exchange servers.




回答3:


Using IMAP is a way to go. You can use Mail.dll IMAP component:

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

    imap.SelectInbox();
    List<long> uids = imap.Search(Flag.Unseen);
    foreach (long uid in uids)
    {
          var eml = imap.GetMessageByUID(uid);
          IMail message = new MailBuilder()
                    .CreateFromEml(eml);

          Console.WriteLine(message.Subject);
          Console.WriteLine(message.Text); 
    }
    imap.Close(true);
}

You can download it here: Mail.dll email component.




回答4:


I am trying http://csharpopensource.com/openpopdotnet.aspx, it have been recently updated and it is not bad. It lack good documentation but it also work with gmail/ssl.



来源:https://stackoverflow.com/questions/211037/automated-processing-of-an-email-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!