MimeMessageExtensionsEncryptAsync Method

Asynchronously encrypt the message to the sender and all of the recipients using the specified cryptography context.

Definition

Namespace: MimeKit.Cryptography
Assembly: MimeKit.Cryptography (in MimeKit.Cryptography.dll) Version: 5.0.0
C#
public static Task EncryptAsync(
	this MimeMessage message,
	CryptographyContext ctx,
	CancellationToken cancellationToken = default
)

Parameters

message  MimeMessage
The message to encrypt.
ctx  CryptographyContext
The cryptography context.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Return Value

Task
An asynchronous task context.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type MimeMessage. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

If either of the Resent-Sender or Resent-From headers are set, then the message will be encrypted to all of the addresses specified in the Resent headers (Resent-Sender, Resent-From, Resent-To, Resent-Cc, and Resent-Bcc), otherwise the message will be encrypted to all of the addresses specified in the standard address headers (Sender, From, To, Cc, and Bcc).

Exceptions

ArgumentNullException ctx is .
ArgumentException An unknown type of cryptography context was used.
InvalidOperationException

The message Body has not been set.

-or-

No recipients have been specified.

OperationCanceledException The operation was canceled via the cancellation token.
CertificateNotFoundException A certificate could not be found for one or more of the recipients.
PublicKeyNotFoundException The public key could not be found for one or more of the recipients.

See Also