using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net.Mail;
namespace sendEmail.Controllers
{
public class SendController : Controller
{
//
// GET: /SendEmail/
public ActionResult Index()
{
return View();
}
public ActionResult sendEmail()
{
return View();
}
[HttpPost]
public ActionResult sendEmail(FormCollection fc)
{
MailMessage msg = new MailMessage();
msg.To.Add("邮箱1@qq.com");
msg.To.Add("邮箱2@163.com");
msg.From = new MailAddress("邮箱@qq.com", "发件人", System.Text.Encoding.UTF8);
msg.Subject = "这是测试邮件";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = "邮件内容";//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("邮箱@qq.com", "密码");
//注册的邮箱和密码
client.Host = "smtp.qq.com";
object userState = msg;
try
{
client.SendAsync(msg, userState);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return View();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net.Mail;
namespace sendEmail.Controllers
{
public class SendController : Controller
{
//
// GET: /SendEmail/
public ActionResult Index()
{
return View();
}
public ActionResult sendEmail()
{
return View();
}
[HttpPost]
public ActionResult sendEmail(FormCollection fc)
{
MailMessage msg = new MailMessage();
msg.To.Add("邮箱1@qq.com");
msg.To.Add("邮箱2@163.com");
msg.From = new MailAddress("邮箱@qq.com", "发件人", System.Text.Encoding.UTF8);
msg.Subject = "这是测试邮件";//邮件标题
msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
msg.Body = "邮件内容";//邮件内容
msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
msg.IsBodyHtml = false;//是否是HTML邮件
msg.Priority = MailPriority.High;//邮件优先级
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("邮箱@qq.com", "密码");
//注册的邮箱和密码
client.Host = "smtp.qq.com";
object userState = msg;
try
{
client.SendAsync(msg, userState);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return View();
}
}
}