Click or drag to resize
MimeKit

MimeContent Class

Encapsulates a content stream used by MimePart.
Inheritance Hierarchy
SystemObject
  MimeKitMimeContent

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll) Version: 4.7.1
Syntax
C#
public class MimeContent : IMimeContent, 
	IDisposable

The MimeContent type exposes the following members.

Constructors
 NameDescription
Public methodMimeContent Initialize a new instance of the MimeContent class.
Top
Properties
 NameDescription
Public propertyEncoding Get or set the content encoding.
Public propertyNewLineFormat Get the new-line format, if known.
Public propertyStream Get the content stream.
Top
Methods
 NameDescription
Public methodCode exampleDecodeTo Decode the content stream into another stream.
Public methodCode exampleDecodeToAsync Asynchronously decode the content stream into another stream.
Public methodDispose Release all resources used by the MimeContent object.
Protected methodDispose(Boolean) Release the unmanaged resources used by the MimeContent and optionally releases the managed resources.
Public methodEquals
(Inherited from Object)
Protected methodFinalize Releases unmanaged resources and performs other cleanup operations before the MimeContent is reclaimed by garbage collection.
(Overrides ObjectFinalize)
Public methodGetHashCode
(Inherited from Object)
Public methodGetType
(Inherited from Object)
Protected methodMemberwiseClone
(Inherited from Object)
Public methodOpen Open the decoded content stream.
Public methodToString
(Inherited from Object)
Public methodWriteTo Copy the content stream to the specified output stream.
Public methodWriteToAsync Asynchronously copy the content stream to the specified output stream.
Top
Remarks
A MimeContent represents the content of a MimePart. The content has both a stream and an encoding (typically Default).
Example
C#
foreach (var attachment in message.Attachments) {
    if (attachment is MessagePart) {
        var fileName = attachment.ContentDisposition?.FileName;
        var rfc822 = (MessagePart) attachment;

        if (string.IsNullOrEmpty (fileName))
            fileName = "attached-message.eml";

        using (var stream = File.Create (fileName))
            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