public ActionResult ContributePost(ContributeModel model) { try { _indexAction.Contribute(model); } catch (Exception exception) { return RedirectToMessage(exception.Message); } return RedirectToMessage("投稿成功!"); }
public void Contribute(ContributeModel model) { var userName = AppConfig.SmtpUserName; var content = string.Format("标题:{0}<br/>作者:{1}<p/>正文:{2}", model.Title, model.Author, model.Content); var message = new Message(); message.Subject = "【新闻投稿】" + model.Title; message.From = userName; message.Charset = Encoding.GetEncoding("GB2312"); message.BodyHtml = content; message.To.Add(AppConfig.ContributeSendTo); // 设置SMTP var smt = new Smtp { UserName = userName, Password = AppConfig.SmtpPassword, HostName = AppConfig.SmtpServer, Domain = AppConfig.SmtpDomain, Port = short.Parse(AppConfig.SmtpPort), Authentication = SmtpAuthentication.Login }; smt.Send(message); }