如何从控制器发送电子邮件?我在数据库中有电子邮件地址,因此我从基地收到此电子邮件,并向此电子邮件发送特殊短信.我不需要使用View. 开始了: 你的代码: System.Net.Mail.MailMessage
你的代码:
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.From = new System.Net.Mail.MailAddress("yourname@yourdomain.com"); message.To.Add(new System.Net.Mail.MailAddress("receiver@receiverdomain.com")); message.IsBodyHtml = true; message.BodyEncoding = Encoding.UTF8; message.Subject = "subject"; message.Body = "hello receiver"; System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); client.Send(message);
而你的web.config:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.net> <mailSettings> <smtp from="yourname@yourdomain.com" deliveryMethod="Network"> <network host="smtp.yourprovider.com" port="587" userName="yourname@yourdomain.com" password="yourpass" enableSsl="true" /> </smtp> </mailSettings> </system.net> ...