Bug 8710 - System.net.mail.smtpExceptiom
Summary: System.net.mail.smtpExceptiom
Status: RESOLVED NORESPONSE
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-12-01 01:27 UTC by Nazish Ansari
Modified: 2013-12-05 18:35 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Nazish Ansari 2012-12-01 01:27:58 UTC
When running the below code, getting "Unhandled Exception:
System.Net.Mail.SmtpException"

This code is for sending mail...
its work fine with windows application but am getting runtime error on mono for android 
someone tell me that System.net.mail is part of the System.dll assembly. but i dnt know how to use it in my monodroid application


additional namespace is :  "using System.Net.Mail;"

> string username = "abc@xyz.com";
> string password = "1234567890";
> System.Net.NetworkCredential nc = new
> System.Net.NetworkCredential(username, password);
> MailMessage MailMessage = new MailMessage();
> MailMessage.To.Add("pqr@xyz.com");
> MailMessage.Subject = "here is the subject";
> MailMessage.From = new System.Net.Mail.MailAddress("abc@xyz.com");
> MailMessage.Body = "Application run time was ";
> System.Net.Mail.SmtpClient SmtpClient = new System.Net.Mail.SmtpClient("
> smtp.gmail.com");
> SmtpClient.UseDefaultCredentials = false;
>
> SmtpClient.EnableSsl = true;
> SmtpClient.Credentials = nc;
> SmtpClient.Port = 587;
> SmtpClient.Send(MailMessage);

Runs fine on Windows.
Running Mono for android 4.2.7
Visual studio 2010
Comment 1 Jonathan Pryor 2012-12-07 17:28:55 UTC
What is the exception + full stack trace when you run this?

Is this a Debug or a Release app?

When I run the above code in a Release app, it fails:

> Unhandled Exception:
> System.Net.Mail.SmtpException: Message could not be sent. ---> System.Net.Sockets.SocketException: No such host is known
>   at System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist)
>   at System.Net.Dns.GetHostByName (System.String hostName)
>   at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress)
>   at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress)
>   at System.Net.Sockets.TcpClient.Connect (System.String hostname, Int32 port)
>   at System.Net.Sockets.TcpClient..ctor (System.String hostname, Int32 port)
>   at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage message)
>   at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message)

This is because by default Release apps don't have INTERNET permission. Please run it.

When I run the above code in a Debug build, it fails with: 

> UNHANDLED EXCEPTION: System.Net.Mail.SmtpException: Message could not be sent. ---> System.IO.IOException: The authentication or decryption has failed. ---> System.InvalidOperationException: SSL authentication error: RemoteCertificateNotAvailable, RemoteCertificateChainErrors
>   at System.Net.Mail.SmtpClient.<callback>m__2 (System.Object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors sslPolicyErrors)
>   at (wrapper delegate-invoke) <Module>:invoke_bool__this___object_X509Certificate_X509Chain_SslPolicyErrors (object,System.Security.Cryptography.X509Certificates.X509Certificate,System.Security.Cryptography.X509Certificates.X509Chain,System.Net.Security.SslPolicyErrors)
>   at System.Net.Security.SslStream+<BeginAuthenticateAsClient>c__AnonStoreyB.<>m__8 (System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Int32[] certErrors)
>   at Mono.Security.Protocol.Tls.SslClientStream.OnRemoteCertificateValidation (System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Int32[] errors)
>   at Mono.Security.Protocol.Tls.SslStreamBase.RaiseRemoteCertificateValidation (System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Int32[] errors)
>   at Mono.Security.Protocol.Tls.SslClientStream.RaiseServerCertificateValidation (System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Int32[] certificateErrors)
>   at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.validateCertificates (Mono.Security.X509.X509CertificateCollection certificates)
>   at Mono.Security.Protocol.Tls.Handshake.Client.TlsServerCertificate.ProcessAsTls1 ()
>   at Mono.Security.Protocol.Tls.Handshake.HandshakeMessage.Process ()
>   at Mono.Security.Protocol.Tls.ClientRecordProtocol.ProcessHandshakeMessage (Mono.Security.Protocol.Tls.TlsStream handMsg)
>   at Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback (IAsyncResult asyncResult)
>   --- End of inner exception stack trace ---
>   at Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback (IAsyncResult asyncResult)
>   --- End of inner exception stack trace ---
> at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage)
> at MonoAndroidTestProject.Activity1.OnCreate (Android.OS.Bundle)
> at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr)
> at (wrapper dynamic-method) object.a085695b-4281-4540-ac20-97c240ef6a9f (intptr,intptr,intptr)

This I'm unsure about. Perhaps the username, password, or some other data is incorrect?
Comment 2 PJ 2013-11-19 17:04:49 UTC
This bug has been in the NEEDINFO state with no changes for the last 90 days. Can we put this back into the NEW or CONFIRMED state, or are we still awaiting response?

If there is no change in the status of this bug over the next two weeks, this bug will be marked as NORESPONSE.
Comment 3 PJ 2013-12-05 18:35:00 UTC
This bug has not been changed from the NEEDINFO state since my previous comment, marking as RESOLVED NORESPONSE.

Please feel free to REOPEN this bug at any time if you are still experiencing the issue. Please add the requested information and set the bug back to the NEW (or CONFIRMED) state.