简体   繁体   English

电子邮件更改发件人:地址

[英]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 不会影响任何现有流程,请尝试此

  • get the From Email-ID (fromAddress) from DataBase 从数据库获取发件人的电子邮件ID(fromAddress)
  • Configure the From Email_ID (fromAddress) in Web Config File which u can Access it for the Entire application. 在Web Config文件中配置From Email_ID(fromAddress),您可以为整个应用程序访问它。

u can change them whenever u want. 您可以随时更改它们。 without changing the C# source code. 无需更改C#源代码。

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

相关问题 如何更改电子邮件地址字段? - How to change email FROM address field? 从MVCMailer 4.5中的电子邮件地址更改 - Change From email address in MVCMailer 4.5 从动态crm 2011回复时如何将回复电子邮件地址更改为队列的电子邮件地址? - How to change the reply email address to the queue's email address when replying from dynamic crm 2011? 电子邮件支持部分,用户地址为“发件人地址” - Email Support section with the users address as "From address" 从appSettings中拉取email地址 - Pull email address from appSettings 我们可以在Azure AD B2C中的“配置文件编辑策略”中更改用户的电子邮件地址吗? - Can we change email address of user from “Profile editing policies” in Azure AD B2C? 使用System.Net.Mail.SmtpClient,更改SMTP FROM电子邮件地址 - Using System.Net.Mail.SmtpClient, change the SMTP FROM email address 更改outlook html电子邮件中呈现的电子邮件地址上的超链接的颜色 - Change the colour of a hyperlink on an email address that is rendered in outlook html email 从电子邮件地址提取别名的有效方法 - Effective way of extracting alias from email address 从文本框中获取电子邮件地址并发送 - Getting email address from text box and send it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM