Click or drag to resize
MimeKit

MimeMessageAttachments Property

Gets the attachments.

Namespace:  MimeKit
Assembly:  MimeKit (in MimeKit.dll) Version: 2.0.7.0
Syntax
C#
public IEnumerable<MimeEntity> Attachments { get; }

Property Value

Type: IEnumerableMimeEntity
The attachments.
Remarks
Traverses over the MIME tree, enumerating all of the MimeEntity objects that have a Content-Disposition header set to "attachment".
Examples
C#
foreach (var attachment in message.Attachments) {
    if (attachment is MessagePart) {
        var fileName = attachment.ContentDisposition?.FileName :
            (attachment.ContentType.Name ?? "attached.eml");
        var rfc822 = (MessagePart) attachment;

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

        using (var stream = File.Create (fileName))
            part.Content.DecodeTo (stream);
    }
}
See Also