简体   繁体   中英

How to add a sender (on behalf of user) to the email when using Office 365 as relay in ASP.net

In my system it has an option that the users in the system can contact our customer support when they need a support from the system. Users simply enter their Name, Email and the Question they have and send the request to the support.

Until now I have handle this from my end and now I need to move that part to another 3rd party service which do these type of support services.

So once the user submit the questions I'm sending that question as an email to the 3rd party support service and 3rd party service suppose to send an automated reply to the users first before they address the question.

Since this email sending from our end its from address always will be our email address and I'm the one receive these automated emails not the end users.

I need to overwrite from email to user email. I tried with add sender with from email address but I get " mail box unavailable error ".

I use office365 account as the relay and I need to know that this issue I get because of Office365 limitation or not.

Is there any other way I can achieve this? In below you can find the code I'm using to send the email. But set "Sender"is not working for me. It would be great someone can help me with this. Thanks in advance.

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.From = info@<our_domain_name>.com
mail.To = <3rdParty_support_email>
mail.IsBodyHtml = true;
mail.Subject = "Test Support email";
mail.Body = <Some HTML content>;
mail.IsBodyHtml = true;
**mail.Sender = <User_Email>**

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(<email_MailHost>);
smtp.Port = <port_number>;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential(<userName>, <password>);

try
{
    smtp.Send(mail);
    return true;
}
catch(Exception ex)
{
    return false;
} 

回复电子邮件标题正是您要寻找的。

mail.ReplyTo = new MailAddress("third_party@test.com");

or

mail.ReplyToList.Add(new MailAddress("third_party1@test.com"));
mail.ReplyToList.Add(new MailAddress("third_party2@test.com"));
mail.ReplyToList.Add(new MailAddress("third_partyn@test.com"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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