<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MailKit",
  "identifier" : "/documentation/MailKit/MEMessageSecurityHandler",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "MailKit"
    ],
    "preciseIdentifier" : "c:objc(pl)MEMessageSecurityHandler"
  },
  "title" : "MEMessageSecurityHandler"
}
-->

# MEMessageSecurityHandler

An object that digitally signs or encrypts messages the user sends and receives.

```
@MainActor protocol MEMessageSecurityHandler : MEMessageDecoder, MEMessageEncoder
```

## Overview

When users enable an extension that implements a message security handler, Mail passes incoming and outgoing message content to the extension for encryption and digital signing.

To encompass the symmetrical halves for encoding and decoding, MailKit defines two protocols that [`MEMessageSecurityHandler`](/documentation/MailKit/MEMessageSecurityHandler) conforms to:

- [`MEMessageEncoder`](/documentation/MailKit/MEMessageEncoder): Methods that encrypt and digitally sign an email message.
- [`MEMessageDecoder`](/documentation/MailKit/MEMessageDecoder): Methods that decrypt email messages and verify digital signatures.

As the user composes a mail message, MailKit calls [`getEncodingStatus(for:composeContext:completionHandler:)`](/documentation/MailKit/MEMessageEncoder/getEncodingStatus(for:composeContext:completionHandler:)) to determine if the handler can sign or encrypt the message. The handler indicates the capabilities by providing an instance of [`MEOutgoingMessageEncodingStatus`](/documentation/MailKit/MEOutgoingMessageEncodingStatus). Mail reflects this status in the compose window by enabling the appropriate buttons to let the user choose how to encode the message. When the user sends the message, MailKit invokes the [`encode(_:composeContext:completionHandler:)`](/documentation/MailKit/MEMessageEncoder/encode(_:composeContext:completionHandler:)) method, and indicates whether the user chose to encrypt or sign the message.

When MailKit needs the original message content, it invokes the handler’s [`decodedMessage(forMessageData:)`](/documentation/MailKit/MEMessageDecoder/decodedMessage(forMessageData:)) method. This method creates an instance of [`MEDecodedMessage`](/documentation/MailKit/MEDecodedMessage) that includes the raw decoded message data and the details of who signed the message in an instance of [`MEMessageSecurityInformation`](/documentation/MailKit/MEMessageSecurityInformation).

> Note:
> MailKit stores the encrypted and signed message content. Therefore, MailKit may ask a message security handler to decode the same message repeatedly over time when it needs the decoded original message content.

To indicate that your extension contains a message security handler, add `MEMessageSecurityHandler` to the <doc://com.apple.documentation/documentation/BundleResources/Information-Property-List/NSExtension/NSExtensionAttributes/MEExtensionCapabilities> array in the extension’s `Info.plist` file:

```plist
<key>NSExtensionAttributes</key>
<dict>
    <key>MEExtensionCapabilities</key>
    <array>
        <string>MEMessageSecurityHandler</string>
    </array>
</dict>
```

## Topics

### Encrypting and Signing Messages

[`MEMessageEncoder`](/documentation/MailKit/MEMessageEncoder)

An object that encrypts or digitally signs outgoing messages.

[`MEEncodedOutgoingMessage`](/documentation/MailKit/MEEncodedOutgoingMessage)

An object that contains the signed or encrypted representation of a message’s RFC 2822 data.

[`MEOutgoingMessageEncodingStatus`](/documentation/MailKit/MEOutgoingMessageEncodingStatus)

An object that contains information about security measures the user can apply when composing a message.

[`MEMessageEncodingResult`](/documentation/MailKit/MEMessageEncodingResult)

An object that contains a signed or encrypted message, or errors that indicate failure to encode the message.

### Decrypting Messages and Verifying Signatures

[`MEMessageDecoder`](/documentation/MailKit/MEMessageDecoder)

An object that decrypts messages and provides details about digital signatures.

[`MEDecodedMessage`](/documentation/MailKit/MEDecodedMessage)

An object that contains the RFC 2822 data for a message, without encryption or digital signatures.

[`MEMessageSigner`](/documentation/MailKit/MEMessageSigner)

An object that contains details about the person who signed a message.

[`MEMessageSecurityInformation`](/documentation/MailKit/MEMessageSecurityInformation)

An object that contains details about a message’s content, such as if it’s encrypted and who digitally signed it.

### Displaying Signature Details

[`-  extensionViewControllerForMessageSigners:`](/documentation/MailKit/MEMessageSecurityHandler/extensionViewController(signers:))

Returns a view controller that displays details about a message’s digital signature.

### Instance Methods

[`-  extensionViewControllerForMessageContext:`](/documentation/MailKit/MEMessageSecurityHandler/extensionViewController(messageContext:))

[`-  primaryActionClickedForMessageContext:completionHandler:`](/documentation/MailKit/MEMessageSecurityHandler/primaryActionClicked(forMessageContext:completionHandler:))

## Relationships

### Inherits From

[`MEMessageDecoder`](/documentation/MailKit/MEMessageDecoder)

[`MEMessageEncoder`](/documentation/MailKit/MEMessageEncoder)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)