Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Mailkit AOT/Net9 compatible #1844

Closed
PaulTaro opened this issue Nov 15, 2024 · 9 comments
Closed

Make Mailkit AOT/Net9 compatible #1844

PaulTaro opened this issue Nov 15, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@PaulTaro
Copy link

I am using Mailkit in my app for Windows, Android, and iOS. For iOS I must target SDK V17 now. This is supported by Microsoft.iOS only, not more by Xamarin. To produce a release with VS2022, all assemblies should be AOT compatible. Currently I can't release my app for iOS because MailKit is not AOT compatible.

@jstedfast
Copy link
Owner

D'oh, I was just hanging out with the Microsoft.iOS and Android team leads for the past 3 days. Wish I had gotten this request a day or two ago.

Oh well. It's probably as simple as adding net-9.0 to the tfm's?

@PaulTaro
Copy link
Author

jstedfast added a commit to jstedfast/MimeKit that referenced this issue Nov 17, 2024
jstedfast added a commit to jstedfast/MimeKit that referenced this issue Nov 17, 2024
@jstedfast jstedfast added the enhancement New feature or request label Nov 28, 2024
@jstedfast
Copy link
Owner

jstedfast commented Nov 29, 2024

It seems all of the AOT compatibility issues are in MimeKit and not MailKit.

I've fixed the core MimeKit stuff to be AOT compatible (e.g. MimeKitLite should be completely AOT compatible now), but MimeKit still isn't because of all of the reflection needed in the MimeKit.Cryptography namespace - specifically the SqliteCertificateDatabase.

I don't see a path to fixing this, unfortunately.

jstedfast added a commit to jstedfast/MimeKit that referenced this issue Nov 30, 2024
Part of the ongoing work for jstedfast/MailKit#1844
jstedfast added a commit that referenced this issue Dec 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Part of the ongoing work for issue #1844
@rosen-vladimirov
Copy link

Hey @jstedfast ,
I see you've added AOT compatibility test, which seems to be passing, so is AOT supported at the moment?

@jstedfast
Copy link
Owner

Only if you use the MimeKitLite and MailKitLite packages.

@PaulTaro
Copy link
Author

PaulTaro commented Mar 25, 2025

I am now using MailKitLite with AOT compilation for iOS and it functions well. Unfortunally this is not true for Android. The following exception occurs when SendMailAsync is called both in release mode and in debug mode even that the same code is used as for iOS:

MailKit.Security.SslHandshakeException: An error occurred while attempting to establish an SSL or TLS connection.

The server's SSL certificate could not be validated for the following reasons:
• The server certificate has the following errors:
• The certificate's revocation status could not be determined.
• An intermediate certificate has the following errors:
• Unable to determine revocation status due to network error

---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> Interop+AndroidCrypto+SslException: Exception of type 'Interop+AndroidCrypto+SslException' was thrown.
--- End of inner exception stack trace ---
at System.Net.Security.SslStream.d__157`1[[System.Net.Security.SyncReadWriteAdapter, System.Net.Security, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()
at System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
at MailKit.Net.Smtp.SmtpClient.SslHandshake(SslStream ssl, String host, CancellationToken cancellationToken) in D:\src\MailKit\MailKit\Net\Smtp\SmtpClient.cs:line 1309
at MailKit.Net.Smtp.SmtpClient.PostConnect(Stream stream, String host, Int32 port, SecureSocketOptions options, Boolean starttls, CancellationToken cancellationToken) in D:\src\MailKit\MailKit\Net\Smtp\SmtpClient.cs:line 1359
--- End of inner exception stack trace ---
at MailKit.Net.Smtp.SmtpClient.PostConnect(Stream stream, String host, Int32 port, SecureSocketOptions options, Boolean starttls, CancellationToken cancellationToken) in D:\src\MailKit\MailKit\Net\Smtp\SmtpClient.cs:line 1376
at MailKit.Net.Smtp.SmtpClient.Connect(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken) in D:\src\MailKit\MailKit\Net\Smtp\SmtpClient.cs:line 1507
at KubiConsult.Mail.MailKit.SendMessage(MimeMessage message) in ...

@PaulTaro
Copy link
Author

PaulTaro commented Mar 25, 2025

PS: When I use the same code and the same MailkitLite version with the NetStandard version of my app sending an e-mail under Android functions well.

@jstedfast
Copy link
Owner

That exception doesn't have any thing to do with AOT issues - it looks like an SSL certificate revocation check error (due to some sort of network error). This makes sense that it's different on Android vs iOS because the underlying SSL implementation is being used for this afaik (by the System.Security SslStream class).

Try client.CheckCertificateRevocation = false;

@PaulTaro
Copy link
Author

Thank you for the explanation. It now also works on Android.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants