Sending mail with Android and C#, it never returns from SmtpServer.Send

DominusDRR

Member
Joined
Nov 19, 2021
Messages
10
Programming Experience
5-10
Hi.

I have the following code that works perfectly with C# and WPF:
Sending an email with SmtpClient:
String emaailO = "xxxxxxx@outlook.com";
String passwordO = "123456789";
SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
var mail = new MailMessage();
mail.From = new MailAddress(emaailO);
mail.To.Add(etEmailUser.Text);
mail.Subject = "Subject";
mail.IsBodyHtml = true;

mail.Body = "email body";
SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(emaailO, passwordO);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);

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 some kind of error occurs.

email.png


I have also tried putting this code in an asynchronous task, but the result is the same.

Any comments or suggestions are welcome.

Could I share with you the link to a very simple example code so that you can check the problem that happens to me?
 
I vaguely recall that you need to give apps permissions to send email.

Although you are using live.com above, if you use gmail, you need to tell Gmail to be less secure. See
 
I vaguely recall that you need to give apps permissions to send email.

Although you are using live.com above, if you use gmail, you need to tell Gmail to be less secure. See
Hi.

Thanks for writting.


I've tried, but it doesn't work either. I feel like it's something else that I need to activate, something regarding the internet.

I have activated the permissions on the manifest file, but something else is missing.
 
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 some kind of error occurs.

I don't know if you can do this on the 'droid, but can you stop the current hung thread and look at the callstack for that thread to see where it's stuck? That would mean getting the symbols not only for your app, but for everything else below that Send() method, and potentially the Android symbols as well.
 
I don't know if you can do this on the 'droid, but can you stop the current hung thread and look at the callstack for that thread to see where it's stuck? That would mean getting the symbols not only for your app, but for everything else below that Send() method, and potentially the Android symbols as well.

Are you referring to this?

1637340273334.png
 
Yup. Looks like it's waiting infinitely to connect to the SMTP server.
 
Someone else helped me test my code on another PC with VS and it works fine, it's something else on my computer.

I think it may be the antivirus, but the problem happens both in a virtual mobile phone and in a real one.

The only difference is that I have version 16.11.3 of VS 2019 and who helped me 16.11.5, but I doubt that this is the cause.

The last thing I'm missing is testing the code on the phone that my friend helped me test.
 
Last edited:
Good luck narrowing down who is blocking your Internet traffic from your phone.
 

Latest posts

Back
Top Bottom