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

Send mail via System.Net.Mail.SmtpClient isn't working on Android, but on Windows #9587

Closed
tsjdev-apps opened this issue Aug 22, 2022 · 9 comments
Labels
platform/android 🤖 t/bug Something isn't working

Comments

@tsjdev-apps
Copy link

Description

I've created a small sample trying to send an email using theSystem.Net.Mail.SmtpClient. The sample is working on Windows, but not on Android. An Interop+AndroidCrypto+SslException is thrown.

Steps to Reproduce

  1. Create a File > New .NET MAUI App
  2. Create a System.Net.Mail.SmtpClient and calling the SendMailAsync() on Android
  3. An Interop+AndroidCrypto+SslException is thrown
  4. Run the same code on Windows and the email is sent

I've tried using an outlook.com mail address with the smtp-mail.outlook.com host.

See the following basic sample:
MauiSendMailSample.zip

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android

Did you find any workaround?

No response

Relevant log output

{System.Net.Mail.SmtpException: Failure sending mail.
 ---> 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.<ForceAuthenticationAsync>d__175`1[[System.Net.Security.AsyncReadWriteAdapter, System.Net.Security, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()
   at System.Threading.Tasks.TaskToApm.End(IAsyncResult asyncResult)
   at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
   at System.Net.TlsStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
   at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.TlsStreamAuthenticateCallback(IAsyncResult result)
--- End of stack trace from previous location ---
   at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result)
   at System.Net.Mail.SmtpConnection.EndGetConnection(IAsyncResult result)
   at System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result)
   at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result)
   --- End of inner exception stack trace ---
   at MauiSendMailSample.MainPage.OnMailButtonClicked(Object sender, EventArgs e) in MauiSendMailSample\MauiSendMailSample\MainPage.xaml.cs:line 36}
@tsjdev-apps tsjdev-apps added the t/bug Something isn't working label Aug 22, 2022
@janseris
Copy link

janseris commented Aug 22, 2022

Seems there are SSL issues with Android in. NET in multiple technologies.
Adding to my list, it is currently:
gRPC, WebSocket, SQL Server and SMTP

dotnet/android#7277

@jfversluis
Copy link
Member

As pointed out this seems to be at least a layer deeper on the Android bindings or maybe even on the plugin/.NET runtime in this case. Unfortunately this is not something that we can do something about in the .NET MAUI project.

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2022
@janseris
Copy link

@jfversluis can you give a tip how to solve that? Where to report etc.? Thank you

@tsjdev-apps
Copy link
Author

I just tested the same sample on Xamarin.Forms and on Android/UWP it is working like expected.
Only .NET MAUI Android isn't working as expected.

@MohammdaSalah
Copy link

So any workaround to this?

@knocte
Copy link
Contributor

knocte commented Aug 28, 2022

I just tested the same sample on Xamarin.Forms and on Android/UWP it is working like expected.
Only .NET MAUI Android isn't working as expected.

If this is true then this issue needs to be reopened @jfversluis

@tsjdev-apps
Copy link
Author

I just tested the same sample on Xamarin.Forms and on Android/UWP it is working like expected.
Only .NET MAUI Android isn't working as expected.

If this is true then this issue needs to be reopened @jfversluis

For me this exception only got raised if I'm running the sample on an emulator for .NET MAUI. If I'm running the code on a real device (I've tested with Android 11 and Android 12) it is also running.

The Xamarin version is running on an emulator and on a real device.

@dmsch
Copy link

dmsch commented Sep 20, 2022

This issue also occurs with SignalR on Android 8.0.
With Android 9.0 and above, SignalR works.

@janseris
Copy link

janseris commented Sep 20, 2022

This issue also occurs with SignalR on Android 8.0. With Android 9.0 and above, SignalR works.

Could you create a new issue? I think @jfversluis doesn't plan to reopen this one
I'll be happy to track it because this seems like a much broader problem with Android SSL providers

@ghost ghost locked as resolved and limited conversation to collaborators Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants