jstedfast / MailKit

A cross-platform .NET library for IMAP, POP3, and SMTP.

Home Page:http://www.mimekit.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add an Example for MimeMessage.Attachments Property

nitechservices opened this issue · comments

Please add an example for MimeMessage.Attachments Property.

TODO (optional): Describe a specific scenario you would like to see addressed.

Help Topic: http://www.mimekit.net/docs/html/P_MimeKit_MimeMessage_Attachments.htm

I have examples of this in the README and FAQ, but I should probably also add it to the API docs.

foreach (var attachment in message.Attachments) {
    var fileName = attachment.ContentDisposition?.FileName ?? attachment.ContentType.Name;

    using (var stream = File.Create (fileName)) {
        if (attachment is MessagePart) {
            var rfc822 = (MessagePart) attachment;

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

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

The property already has/had an example on the API docs website. I'm not sure why you requested an example when one already existed?