0

I have to generate the mail to their mail address specified at the time of the registration to specify the username and password. So i tried the following code to send email but the email is not generated showing me either "Failure sending mail" or "Connection timed out". So please help me to get out of this problem.

Thanks in Advance

try
            {
                System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage();
                message.From = txtFrom.Text.Trim();
                MailMessage objMailMessage = new MailMessage();
                objMailMessage.From = new MailAddress(txtFrom.Text.Trim());
                objMailMessage.To.Add(new MailAddress(txtTo.Text.Trim()));
                objMailMessage.Subject = txtsubject.Text.Trim();
                objMailMessage.Body = txtMessage.Text.Trim();
                objMailMessage.IsBodyHtml = false;
                SmtpClient objSmtpClient = new SmtpClient();
                objSmtpClient.Host = "smtp.gmail.com";
                objSmtpClient.Port = 587;
                objSmtpClient.Credentials = new System.Net.NetworkCredential(txtFrom.Text.Trim(), txtPassword.Text.Trim());
                objSmtpClient.UseDefaultCredentials = true;
                objSmtpClient.EnableSsl = true;
                objSmtpClient.Send(objMailMessage);
                lblStatus.Text = "Mail has been sent Successfully";
                lblStatus.ForeColor = System.Drawing.Color.Green;
            }
2
Contributors
1
Reply
12
Views
3 Years
Discussion Span
Last Post by Sulaiman_1
0

1.You have to confirm the credential(username and password) with the Gmail.com website
2.If you activated step 2 verification( for asking security code to mobile) or any security question means it gets timeout

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.