繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM