Click or drag to resize
MimeKit

MimeMessageBodyParts Property

Gets the body parts of the message.

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

Property Value

Type: IEnumerableMimeEntity
The body parts.
Remarks
Traverses over the MIME tree, enumerating all of the MimeEntity objects, but does not traverse into the bodies of attached messages.
Examples
C#
foreach (var bodyPart in message.BodyParts) {
    if (!bodyPart.IsAttachment)
        continue;

    if (bodyPart is MessagePart) {
        var fileName = bodyPart.ContentDisposition?.FileName :
            (bodyPart.ContentType.Name ?? "attached.eml");
        var rfc822 = (MessagePart) bodyPart;

        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