Click or drag to resize
MimeKit

AttachmentCollection Class

A collection of attachments.
Inheritance Hierarchy
SystemObject
  MimeKitAttachmentCollection

Namespace: MimeKit
Assembly: MimeKit (in MimeKit.dll) Version: 4.7.1
Syntax
C#
public class AttachmentCollection : IList<MimeEntity>, 
	ICollection<MimeEntity>, IEnumerable<MimeEntity>, IEnumerable

The AttachmentCollection type exposes the following members.

Constructors
 NameDescription
Public methodAttachmentCollection Initialize a new instance of the AttachmentCollection class.
Public methodAttachmentCollection(Boolean) Initialize a new instance of the AttachmentCollection class.
Top
Properties
 NameDescription
Public propertyCount Get the number of attachments currently in the collection.
Public propertyIsReadOnly Get whther or not the collection is read-only.
Public propertyItem Get or set the MimeEntity at the specified index.
Top
Methods
 NameDescription
Public methodAdd(MimeEntity) Add an attachment.
Public methodAdd(String, Byte) Add an attachment.
Public methodCode exampleAdd(String, CancellationToken) Add an attachment.
Public methodAdd(String, ContentType, CancellationToken) Add an attachment.
Public methodAdd(String, Byte, ContentType) Add an attachment.
Public methodAdd(String, Stream, CancellationToken) Add an attachment.
Public methodAdd(String, Stream, ContentType, CancellationToken) Add an attachment.
Public methodAddAsync(String, CancellationToken) Asynchronously add an attachment.
Public methodAddAsync(String, ContentType, CancellationToken) Asynchronously add an attachment.
Public methodAddAsync(String, Stream, CancellationToken) Asynchronously add an attachment.
Public methodAddAsync(String, Stream, ContentType, CancellationToken) Asynchronously add an attachment.
Public methodClear Clear the attachment collection.
Public methodClear(Boolean) Clear the attachment collection.
Public methodContains Check if the collection contains the specified attachment.
Public methodCopyTo Copy all of the attachments in the collection to an array.
Public methodEquals
(Inherited from Object)
Protected methodFinalize
(Inherited from Object)
Public methodGetEnumerator Get an enumerator for the list of attachments.
Public methodGetHashCode
(Inherited from Object)
Public methodGetType
(Inherited from Object)
Public methodIndexOf Get the index of the requested attachment, if it exists.
Public methodInsert Insert an attachment at the given index.
Protected methodMemberwiseClone
(Inherited from Object)
Public methodRemove Remove an attachment.
Public methodRemoveAt Remove the attachment at the specified index.
Public methodToString
(Inherited from Object)
Top
Remarks
The AttachmentCollection is only used when building a message body with a BodyBuilder.
Example
C#
            var message = new MimeMessage ();
            message.From.Add (new MailboxAddress ("Joey", "joey@friends.com"));
            message.To.Add (new MailboxAddress ("Alice", "alice@wonderland.com"));
            message.Subject = "How you doin?";

            var builder = new BodyBuilder ();

            // Set the plain-text version of the message text
            builder.TextBody = @"Hey Alice,

What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.

Will you be my +1?

-- Joey
";

            // In order to reference selfie.jpg from the html text, we'll need to add it
            // to builder.LinkedResources and then use its Content-Id value in the img src.
            var image = builder.LinkedResources.Add (@"C:\Users\Joey\Documents\Selfies\selfie.jpg");
            image.ContentId = MimeUtils.GenerateMessageId ();

            // Set the html version of the message text
            builder.HtmlBody = string.Format (@"<p>Hey Alice,<br>
<p>What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.<br>
<p>Will you be my +1?<br>
<p>-- Joey<br>
<center><img src=""cid:{0}""></center>", image.ContentId);

            // We may also want to attach a calendar event for Monica's party...
            builder.Attachments.Add (@"C:\Users\Joey\Documents\party.ics");

            // Now we just need to set the message body and we're done
            message.Body = builder.ToMessageBody ();
See Also