I am working on one project where I want to send mail using smtp.
I have tried below code but it is giving me error as Failed in Sending Mail
try
{
MailMessage message = new MailMessage("From@gmail.com", "to@gmail.com", "Testing Mail", "Testing mail recv");
SmtpClient client = new SmtpClient();
client.Host = "smtp.googlemail.com";
client.Port = 587;
client.UseDefaultCredentials = false;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("myPage@gmail.com", "123@123");
client.Send(message);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
In place of client.Host = "smtp.googlemail.com";
I have Tried some other code as client.Host = "smtp.google.com";
and client.Host = "smtp.gmail.com";
.
also have tried with different Port No as 25
and 587
.
Can anyone tell me what's wrong with this code?
Thank you in Advance.