I want to test connection is established without sending mail.My code is below.I have put wrong email and password but i m not getting any exception.I don't want to test with email send.
try {
SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
NetworkCredential credentials = new NetworkCredential(textboxprimarymail.Text, textBoxpassprimary.Text);
smtpClient.Credentials = credentials;
connectionestablish.Text = "Connetion Established";
connectionestablish.ForeColor = System.Drawing.Color.ForestGreen;
}
catch {
connectionestablish.Text = "Connetion Error";
connectionestablish.ForeColor = System.Drawing.Color.Red;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…