1
我正在與Umbraco合作。我在我的頁面上有一個表格,用戶應該在其中輸入他們的電子郵件地址和應該發送給我的電子郵件的消息。Umbraco電子郵件表格 - 缺少發件人
問題是我基本上只是發送電子郵件給我自己,現在作爲發送者和接收者。從MailMessage構造函數中的from函數做什麼,因爲它沒有設置from地址?
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Net;
using System.Net.Mail;
public class BlogPostSurfaceController : Umbraco.Web.Mvc.SurfaceController
{
public BlogPostSurfaceController() {
}
[HttpPost]
public ActionResult CreateComment(CommentViewModel model)
{
//model not valid, do not save, but return current Umbraco page
if (!ModelState.IsValid)
{
//redirecting)
return CurrentUmbracoPage();
}
SendMail(model);
//redirect to current page to clear the form
return RedirectToCurrentUmbracoPage();
}
[HttpPost]
public int SendMail(CommentViewModel model) {
try{
MailAddress from = new MailAddress(model.Email);
MailAddress to = new MailAddress("[email protected]");
MailMessage mail = new MailMessage(from, to);
mail.Body = model.Message;
SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
catch(Exception ex) {
return -1;
}
return 1;
}
}
呀這是類似的東西我結束了問這裏之前結束。 – gerre