我想使用邮件网络应用程序发送邮件。发送邮件时显示超时错误。帮我找一个合适的解决方案。
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;
}
}
答案 0 :(得分:0)
使用本工作代码。
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);