AttachmentCollectionAddAsync(String, Stream, ContentType, CancellationToken) Method

Asynchronously add an attachment.

Definition

Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public Task<MimeEntity> AddAsync(
	string fileName,
	Stream stream,
	ContentType contentType,
	CancellationToken cancellationToken = default
)

Parameters

fileName  String
The name of the file.
stream  Stream
The content stream.
contentType  ContentType
The mime-type of the file.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Return Value

TaskMimeEntity
The newly added attachment MimeEntity.

Remarks

Asynchronously adds the specified data as an attachment using the supplied Content-Type.

The file name parameter is used to set the Content-Location.

For a list of known mime-types and their associated file extensions, see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

Exceptions

ArgumentNullException

fileName is .

-or-

stream is .

-or-

contentType is .

ArgumentException The specified file path is empty.
IOException An I/O error occurred.
OperationCanceledException The operation was canceled via the cancellation token.

See Also