有谁知道如何更改代码中的发件人电子邮件地址以覆盖 web.config 设置。
我想做的是允许某人填写在线表格,当收件人收到电子邮件时,它将来自发件人的电子邮件地址。
但目前它只是在 web.config 中显示默认值。
-----------------Web.config------------------------
<smtp from="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f1829e9c94dc949c90989db1969c90989ddf929e9c" rel="noreferrer noopener nofollow">[email protected]</a>" deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" />
<specifiedPickupDirectory pickupDirectoryLocation="c:\temp\"/>
</smtp>
public virtual MvcMailMessage DirectotyEmail(string emailTo, string fromName, string arrivalDate, string departureDate, string message)
{
ViewBag.FromName = fromName;
ViewBag.ArrivalDate = arrivalDate;
ViewBag.DepartureDate = departureDate;
ViewBag.Message = message;
return Populate(x =>
{
x.Subject = "Accommodation Enquery form";
x.ViewName = "DirectoryEmail";
x.To.Add(emailTo.ToString());
//x.From.Address("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abdfced8dfebcec6cac2c785c8c4c6" rel="noreferrer noopener nofollow">[email protected]</a>");
x.IsBodyHtml = true;
});
}
X-Sender: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e3d21232b632b232f27220e29232f2722602d2123" rel="noreferrer noopener nofollow">[email protected]</a> << Need this to be the email that user entered when submitting form
X-Receiver: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="34405147407459555d581a575b59" rel="noreferrer noopener nofollow">[email protected]</a>
MIME-Version: 1.0
From: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e3d21232b632b232f27220e29232f2722602d2123" rel="noreferrer noopener nofollow">[email protected]</a> << Need this to be the email that user entered when submitting form
To: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4a0b1a7a094b9b5bdb8fab7bbb9" rel="noreferrer noopener nofollow">[email protected]</a>
Date: 26 Mar 2013 11:08:57 +0000
Subject: Accommodation Enquery form
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
最佳答案
您可以使用 Sender
属性覆盖 Web 配置提供的发件人,并使用 From
属性覆盖发件人地址。这两个属性都需要 MailAddress
对象,因此您需要编写:
return Populate(x =>
{
x.Subject = "Accommodation Enquery form";
x.ViewName = "DirectoryEmail";
x.To.Add(emailTo.ToString());
x.From = new MailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b4f5e484f7b5e565a525715585456" rel="noreferrer noopener nofollow">[email protected]</a>");
x.Sender = new MailAddress("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afdbcadcdbefcac2cec6c381ccc0c2" rel="noreferrer noopener nofollow">[email protected]</a>");
x.IsBodyHtml = true;
});
关于c# - MVCMailer 4.5 中的更改发件人电子邮件地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15635629/