[英]Email change From: address
I'm doing a property listing site and is now preparing a contact form for each property. 我正在做一个财产清单网站,现在正在为每个财产准备联系表格。
As my client is also using a ticketing system which parse emails from a dedicated mailbox, it requires me to configure the contact form to email to the dedicated mailbox for their system to pick it up. 由于我的客户还使用票务系统来解析来自专用邮箱的电子邮件,因此我需要配置联系表单以将电子邮件发送到专用邮箱,以便他们的系统将其提取。 I'm using ASP C#. 我正在使用ASP C#。
I need help on changing the "From" address in the contact form to the sender's email address in the form, codes are as shown below: 在将联系表单中的“发件人”地址更改为表单中发件人的电子邮件地址时,我需要帮助,代码如下所示:
This is my aspx.cs 这是我的aspx.cs
protected void SendMail()
{
var fromAddress = "email@domain.com";
var toAddress = "dedicatedmailbox@domain.com";
const string fromPassword = "password";
string subject = PropertyNameOnContact.Text.ToString();
string body = "Subject: Online Enquiry for " + PropertyNameOnContact.Text + "\n";
body += "Email: " + txtemail.Text + "\n";
body += "From: " + txtname.Text + "\n";
body += "Preferred contact Method: \n" + PreferredContact.Text + "\n";
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
smtp.Send(fromAddress, toAddress, subject, body);
}
For a contact form like this, the address filled in by the user should never be the address used as from address. 对于这样的联系表,用户填写的地址绝不应是用作发件人地址的地址。 It should be the reply-to address. 它应该是回复地址。 This is done so that the receiving mail server can make correct validations. 这样做是为了使接收邮件服务器可以进行正确的验证。
I suggest you create a MailMessage
object, on which you can set all these parameters that the shorthand SmtpClient.Send
doesn't have. 我建议您创建一个MailMessage
对象,在该对象上可以设置速记SmtpClient.Send
没有的所有这些参数。 On that you can add your addresses that should be replied to in MailMessage.ReplyToList
, and the from adress as MailMessage.From
. 在此之后,您可以在MailMessage.ReplyToList
添加应答复的地址,并将发件人地址作为MailMessage.From
。
The SmtpClient.Send
method also accepts a MailMessage
object, so it should be fairly easy. SmtpClient.Send
方法还接受MailMessage
对象,因此它应该相当简单。
Here's the MailMessage object on MSDN: http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx 这是MSDN上的MailMessage对象: http : //msdn.microsoft.com/zh-cn/library/system.net.mail.mailmessage.aspx
As know there are two ways. 众所周知,有两种方法。 which will not Affect any of the existing Process, Try this 不会影响任何现有流程,请尝试此
u can change them whenever u want. 您可以随时更改它们。 without changing the C# source code. 无需更改C#源代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.