MEComposeSessionHandler alert message not shown

When the mail extension invoke allowMessageSendForSession func, the error prompt did not show the error description. What am I missing?

Below is the code:

    enum ComposeSessionError: LocalizedError {

        case invalidRecipientDomain

        

        var errorDescription: String? {

            switch self {

            case .invalidRecipientDomain:

                return "example.com is not a valid recipient domain"

            }

        }

    }

    

    func allowMessageSendForSession(_ session: MEComposeSession) async throws {

        // Before Mail sends a message, your extension can validate the

        // contents of the compose session. If the message isn't ready to be

        // sent, throw an error.



        throw ComposeSessionError.invalidRecipientDomain

    }

Replies

The completion of allowMessageSendForSession() has changed recently. Pass an Error in the completion, see updated Apple docu at https://developer.apple.com/documentation/mailkit/mecomposesessionhandler/3824908-allowmessagesendforsession

The docu contains a code snippet:

enum ComposeSessionError: LocalizedError {
    case invalidRecipientDomain
    
    var errorDescription: String? {
        switch self {
        case .invalidRecipientDomain:
            return "example.com is not a valid recipient domain"
        }
    }
}

func allowMessageSendForSession(_ session: MEComposeSession, completion: @escaping (Error?) -> Void) {
    // Confirm none of the recipients use @example.com.
    if session.mailMessage.allRecipientAddresses.contains(where: { $0.hasSuffix("@example.com")}) {
        completion(ComposeSessionError.invalidRecipientDomain)
    } else {
        completion(nil)
    }
}

Hi Martijn,

I get the same issue as stephenlem on Xcode 13.1 and (13.2 beta 2). The error description is not showing in the dialogue, even when the example code is used. Could it be a bug?

  • Hi Sark,

    Did you notice that there is an if condition in the (my modified) sample? You should send your test email to an email address that ends with "@example.com" to trigger the condition and show the errorDescription in the system Alert.

Add a Comment

Thanks for the response Martijn. Even with the updated code I am not getting the error description to show in the alert. I can definitely trigger the condition, so that's not the issue. It's just that the alert window that comes up doesn't have a description. It looks exactly like the screenshot at the top of this thread.

I've tried even adding 'failureReason', 'helpAnchor', and 'recoverSuggestion' properties to the error. None of them are getting picked up for some reason.

  • That is really weird. It works here since the first Xcode 13 and macOS 12 betas. We now run with production Xcode 13.1 and macOS 12.1 without a glitch. Although I must admit that we still use Objective-C and no Swift. I don't recall if we did run this Swift sample project from Apple successfully, or immediately rewrote the relevant MEComposeSessionHandler logic into ObjC.

Add a Comment

This is still broken in MacOS 12.2

still there on macOS 12.3 and 12.4 beta 1. FB9983235

MacOS 12.4 release still has this issue. Let's hope it will be fixed in MacOS 13.