using System.Net.Mail;//邮件发送需引用
public ActionResult bindStep3(ModelCompany c)
{
.........
..........
...........
MailAddress MessageFrom = new MailAddress("
[email protected]"); //发件人邮箱地址
string MessageTo = company.COMPANY_EMAIL; //收件人邮箱地址
string MessageSubject = "激活验证"; //邮件主题
string MessageBody = "请进行邮箱验证来完成您注册的最后一步,点击下面的链接激活您的帐号:
激活"; //邮件内容 (一般是一个网址链接,生成随机数加验证id参数,点击去网站验证。)
if (SendMail(MessageFrom, MessageTo, MessageSubject, MessageBody))
{
Response.Write("");
}
else
{
Response.Write("");
}
TempData["CompanyBind3"] = company;
return View("bindStep3");
}
public bool SendMail(MailAddress MessageFrom,string MessageTo,string MessageSubject,string MessageBody) //发送验证邮件
{
MailMessage message = new MailMessage();
message.To.Add(MessageTo);
message.From = MessageFrom;
message.Subject = MessageSubject;
message.SubjectEncoding = System.Text.Encoding.UTF8;
message.Body = MessageBody;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true; //是否为html格式
message.Priority = MailPriority.High; //发送邮件的优先等级
SmtpClient sc = new SmtpClient();
sc.EnableSsl = true;//是否SSL加密
sc.Host = "smtp.qq.com"; //指定发送邮件的服务器地址或IP
sc.Port = 587; //指定发送邮件端口
sc.Credentials = new System.Net.NetworkCredential("
[email protected]", "xxxxx"); //指定登录服务器的用户名和密码(注意:这里的密码是开通上面的pop3/smtp服务提供给你的授权密码,不是你的qq密码)
try
{
sc.Send(message); //发送邮件
}
catch(Exception e)
{
Response.Write(e.Message);
return false;
}
return true;
}