[英]Failure sending e-mail in asp.net
這是我的代碼。 我知道這是一個重復的問題,但是我已經訪問了staqckoverflow和codeproject中的所有鏈接,但仍然無法得到答案。
try
{
MailMessage mailmessage = new MailMessage();
mailmessage.To.Add("xxx.com");
mailmessage.From = new MailAddress("xxx.com");
mailmessage.Subject = "Transaction sent for Verification ";
mailmessage.Body = "Hello world,\n\nThis is an ASP.NET test e-mail!";
SmtpClient smtpClient = new SmtpClient(ConfigurationSettings.AppSettings["SmtpAdd"].ToString());
smtpClient.Send(mailmessage);
ClientScript.RegisterStartupScript(this.GetType(), "mailalert", "alert('" + "Mail sent for verification" + "');", true);
}
catch(Exception ex)
{
//Response.Write("Could not send E-mail- error: " + ex.Message);
ClientScript.RegisterStartupScript(this.GetType(), "mailfailure", "alert('" + ex.Message + "');", true);
}
這對你有幫助
MailMessage msg = new MailMessage();
msg.From = new MailAddress(email);
msg.To.Add(new MailAddress("To_address"));
msg.Subject = "You have a WebMail!!";
msg.IsBodyHtml = true;
msg.Body = "Message";
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new NetworkCredential("your mail address", "your password");
smtp.Host = "host name";
smtp.Port = "host number";
smtp.EnableSsl = false;
smtp.Send(msg);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.