public ActionResult SendMail() { MailMessage mss = new MailMessage(); mss.From = new MailAddress("[email protected]"); mss.Body = "testtesttesttesttest"; mss.BodyEncoding = Encoding.UTF8; mss.IsBodyHtml = false; mss.To.Add(new MailAddress("[email protected]")); SmtpClient cliente = new SmtpClient(); cliente.Host = ConfigurationManager.AppSettings["Host"].ToString(); cliente.Port = int.Parse(ConfigurationManager.AppSettings["Port"].ToString()); cliente.UseDefaultCredentials = ConfigurationManager.AppSettings["EnableSsl"].ToString() == "0" ? false : true; cliente.EnableSsl = false; string Username = ConfigurationManager.AppSettings["Username"].ToString(); string Password = ConfigurationManager.AppSettings["Password"].ToString(); System.Net.NetworkCredential credenciais = new System.Net.NetworkCredential(Username, Password); cliente.Credentials = credenciais; cliente.Send(mss); return Content("ok"); }
时间: 2024-11-05 11:51:35