Automatic processing of email messages

I want to write an application (most likely in C #) that checks emails on a specific account, detects attachments and separates them from the folder for processing.

Are there standard .NET classes to accomplish these tasks? If not, what else can I use?

The application will run as a service.

+3


source to share


1 answer


Although there are no APIs in BCL for downloading emails, only sending, it is very well considered that it is now the Microsoft recommended library for sending and receiving emails, it supports POP3, IMAP, SMTP. https://github.com/jstedfast/MailKit

detects attached files and separates them from the folder for processing

I'm going to assume that you want to upload the file to a directory. Fortunately, MailKit is very easy to do, and the author of the library wrote an example here: fooobar.com/questions/717604 / ...

(code taken from link)



foreach (var attachment in message.Attachments) {
    using (var stream = File.Create ("fileName")) {
        if (attachment is MessagePart) {
            var part = (MessagePart) attachment;

            part.Message.WriteTo (stream);
        } else {
            var part = (MimePart) attachment;

            part.ContentObject.DecodeTo (stream);
        }
    }
}

      

The application will run as a service.

It's also very easy to do, you have to write a Windows service. There are many resources out there related to writing one in C #. There's also a template for it in Visual Studio.

enter image description here

+1


source







All Articles