在asp.net中发送电子邮件失败

本文关键字:电子邮件 失败 asp net | 更新日期: 2023-09-27 18:12:01

这是我的代码。我知道这是一个重复的问题,但我已经访问了stackoverflow和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);
    }

在asp.net中发送电子邮件失败

这将帮助你

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);