Umbraco 电子邮件表单 - 缺少发件人

Umbraco email form - missing sender

我正在使用 Umbraco。我的页面上有一个表格,用户应在其中输入他们的电子邮件地址和消息,然后将其发送到我的电子邮件。

问题是我现在基本上只是作为发件人和收件人向自己发送电子邮件。由于 MailMessage 构造函数中的 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;
    }
}

发件人地址只设置邮件中的发件人地址header。大多数 SMTP 服务器不允许您从与您的凭据匹配的帐户以外的电子邮件地址发送电子邮件。

听起来 Hotmail 正在重写您的发件人 header 以匹配您用于登录的帐户。