C# Umbraco电子邮件表单-缺少发件人
我和翁布拉科一起工作。我在我的页面上有一个表单,用户应该在其中输入他们的电子邮件地址和消息,然后将其发送到我的电子邮件 问题是我现在基本上只是把电子邮件发送给我自己,既是发送者又是接收者。MailMessage构造函数中的from没有在中设置from地址,它做什么C# Umbraco电子邮件表单-缺少发件人,c#,asp.net-mvc,umbraco,C#,Asp.net Mvc,Umbraco,我和翁布拉科一起工作。我在我的页面上有一个表单,用户应该在其中输入他们的电子邮件地址和消息,然后将其发送到我的电子邮件 问题是我现在基本上只是把电子邮件发送给我自己,既是发送者又是接收者。MailMessage构造函数中的from没有在中设置from地址,它做什么 using System; using System.Collections.Generic; using System.Web; using System.Web.Mvc; using System.Net; using Syste
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正在重写你的“发件人”标题,以匹配你以前登录的帐户。是的,这是我在询问之前得出的结论。