简体   繁体   English

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

[英]Umbraco email form - missing sender

I'm working with Umbraco. 我正在与Umbraco合作。 I have an form on my page where the user should input their email address and the message which should then be sent to my email. 我的页面上有一个表单,用户应在其中输入他们的电子邮件地址,然后将消息发送到我的电子邮件中。

The problem is I'm basically just sending emails to my self now as both sender and receiver. 问题是我现在基本上只是以发送者和接收者的身份向自己发送电子邮件。 What does the from in the MailMessage constructor do since it's not setting the from address in? 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;
    }
}

The from address only sets the from address in the email header. 发件人地址仅在电子邮件标题中设置发件人地址。 Most SMTP servers will not let you send email from an email address other than the account that matches your credentials. 大多数SMTP服务器不允许您从与您的凭据匹配的帐户以外的电子邮件地址发送电子邮件。

It sounds like Hotmail is rewriting your from header to match the account you used to log in. 听起来好像Hotmail正在重写您的from标头,以匹配您用于登录的帐户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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