Mime MessageBody Parts Property
Get the body parts of the message.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
The body parts.
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public IEnumerable<MimeEntity> BodyParts { get; }Property Value
IEnumerableMimeEntityThe body parts.
Implements
IMimeMessageBodyPartsRemarks
Traverses over the MIME tree, enumerating all the MimeEntity objects,
but does not traverse into the bodies of attached messages.
Example
C#
foreach (var bodyPart in message.BodyParts) {
if (!bodyPart.IsAttachment)
continue;
if (bodyPart is MessagePart) {
var fileName = attachment.ContentDisposition?.FileName ?? attachment.ContentType.Name;
var rfc822 = (MessagePart) attachment;
if (string.IsNullOrEmpty (fileName))
fileName = "attached-message.eml";
// make sure that the filename value does not contain a full path or invalid path characters
fileName = Path.GetFileName (fileName);
using (var stream = File.Create (fileName))
rfc822.Message.WriteTo (stream);
} else {
var part = (MimePart) attachment;
var fileName = part.FileName;
if (string.IsNullOrEmpty (fileName))
fileName = "untitled.dat";
// make sure that the filename value does not contain a full path or invalid path characters
fileName = Path.GetFileName (fileName);
using (var stream = File.Create (fileName))
part.Content.DecodeTo (stream);
}
}