Тайм-аут операции для системы net mail smtpexception

Я хочу отправить почту с помощью почтового веб-приложения. При отправке почты отображается ошибка тайм-аута. Помоги мне найти правильное решение.

protected void btnsubmit_Click(object sender, EventArgs e)
{
    Ticket_MailTableAdapters.tbl_TicketTableAdapter tc;
    tc = new Ticket_MailTableAdapters.tbl_TicketTableAdapter();
    DataTable dt = new DataTable();
    dt = tc.GetEmail(dpl_cate.SelectedValue);
    foreach (DataRow row in dt.Rows)
    {
        string eml = (row["Emp_Email"].ToString());
        var fromAddress = "myMail@gmail.com";
        var toAddress = eml;
        const string fromPassword = "*****";
        string body = "Welcome..";
        // smtp settings
        var smtp = new System.Net.Mail.SmtpClient();
               {
                 smtp.Host = "smtp.gmail.com";
                 smtp.Port = 587;
                 smtp.EnableSsl = true;

                 smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                 smtp.UseDefaultCredentials = true;
                 smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);


               }
        // Passing values to smtp object
         smtp.Send(fromAddress, toAddress, subject, body);
         smtp.Timeout = 600000;
     }
}

1 ответ

Используйте этот рабочий код.

const string vMailFm = "myMail@gmail.com";
var vMailTo = ((txtEmailId.Text == "") ? "myMail@gmail.com" : txtEmailId.Text);
MailMessage vMail = new MailMessage(vMailFm, vMailTo);
const string vSubject = "Center Detail From SAFE";
var vDetails = "";
vDetails += "Dear User,<br><br>";
vDetails += "Kindly find the user details of your registration with SAFE<br><br>";
vDetails += "Your UserName Is - " + vMailTo + "<br>";
vDetails += "Your Password Is - " + Convert.ToString(ViewState["password"]) + "<br>";
vDetails += "<br>";
vDetails += "Registration has been Successfully Completed....";
vDetails += "<br><br>";
vMail.Subject = vSubject;
vMail.Body = vDetails;
vMail.IsBodyHtml = true;
SmtpClient vSmpt = new SmtpClient();
System.Net.NetworkCredential smtpUser = new System.Net.NetworkCredential("myMail@gmail.com", "Password123");
vSmpt.Host = "smtp.gmail.com";
vSmpt.Port = 587;//for local
// vSmpt.Port = 25;//for online
vSmpt.EnableSsl = false;
vSmpt.DeliveryMethod = SmtpDeliveryMethod.Network;
vSmpt.UseDefaultCredentials = false;
vSmpt.Credentials = smtpUser;
vSmpt.Send(vMail);                
Другие вопросы по тегам