question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
knoctecommented, 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

2reactions
tsjdev-appscommented, Aug 25, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NET - Mail server doesn't send mail through SmtpClient.Send
We just added permission for the virtual machine of the web server and the mail is sent normally. SmtpClient client = new SmtpClient();...
Read more >
Sending mail with Android and C#, it never returns from ...
I'm implementing the same thing with android and C#, but when the program reaches SmtpServer.Send it freezes on that line. No exception or...
Read more >
Why doesn't SmtpClient work correctly in VS 2019 version ...
If I use Send, I get the following exception: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport ...
Read more >
SMTP Send No Longer Working? : r/LabVIEW
The error message says: Error 1172 occurred at Error calling method System.Net.Mail.SmtpClient.Send, (System.Reflection.
Read more >
Smtp error while send mail with gmail setting
I am using Gmail setting for sending mail, i got an error like "Failure sending mail." and InnerException as "Unable to read data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found