How can I sort the ping SMTP server so that I can check if the account / password is valid?

I am trying to create a small email tutorial for WPF developers, but I do not want to share it if it has this flagrant error.

This is currently what is happening.

  • user types in username and password.
  • label 'loginstatus' changes to 'Logged', whether it is gibeerish or not.
  • Message object and sending to fields are included.
  • the user clicked the "Submit" button, and if there is an exception (for example, an incorrect username / password), this message box shows it, and loginstatus will be changed to exit the system.

This is very wrong, and I want to fix it.

How can I just "ping" verify the credentials are correct (without sending a test letter).

I am using smtp.gmail.com port 587

Edit This is how I send emails.

var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential(username, password), EnableSsl = true }; try { client.Send(fromEmail, toEmail, subject, body); } catch (Exception e) { MessageBox.Show(e.Message); } 
+4
source share
2 answers

You cannot do this using System.Net.Mail. You must either quit your own or use a third-party product (shameless plugin: like mine - www.aspnetmx.com )

+1
source

If you have control over the SMTP connection, you can only register to verify the username and password without sending a message.

0
source

Source: https://habr.com/ru/post/1299749/


All Articles