[英]Umbraco email form - missing sender
我正在與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("me@hotmail.com");
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("me@hotmail.com", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}
catch(Exception ex) {
return -1;
}
return 1;
}
}
發件人地址僅在電子郵件標題中設置發件人地址。 大多數SMTP服務器不允許您從與您的憑據匹配的帳戶以外的電子郵件地址發送電子郵件。
聽起來好像Hotmail正在重寫您的from標頭,以匹配您用於登錄的帳戶。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.