In my application emil reply chain is working fine. Now when I receive a reply email with change in subject, I want to break the email thread / chain.
Loading
In my application emil reply chain is working fine. Now when I receive a reply email with change in subject, I want to break the email thread / chain.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 3, 2023, 4:15 AM EDT
using System.Net.Mail; // Detect subject change if (receivedEmail.Subject != originalEmail.Subject) { // Create a new email message MailMessage newEmail = new MailMessage(); // Set the new subject newEmail.Subject = receivedEmail.Subject; // Add the recipient newEmail.To.Add(receivedEmail.To.ToString()); // Add the body newEmail.Body = receivedEmail.Body; // Send the email SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587); smtpClient.EnableSsl = true; smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "your_password"); smtpClient.Send(newEmail); }GopiRank #5,293 · 304 reputationPosted Apr 3, 2023, 4:32 AM EDT
I have a thread with multiple messages i want to break the thread when subject of recevied email is changed as new thread.
Tuhin PaulRank #7 · 71.9K reputationPosted Apr 3, 2023, 2:29 PM EDT
To break an email thread or chain, you can modify the subject line of the email. When an email client receives an email with a different subject line, it typically treats it as a new email thread. In your case, you can modify the subject line of the reply email with a unique identifier or text that is different from the original email's subject line.
using System.Text.RegularExpressions; string originalSubject = "RE: Your subject"; string newSubject = "RE: Your subject [NEW THREAD]"; string modifiedSubject = Regex.Replace(originalSubject, "^RE:", newSubject);In the above example, the originalSubject variable contains the subject line of the reply email. The newSubject variable contains the modified subject line with the unique identifier. The modifiedSubject variable contains the final subject line with the newSubject text replacing the RE: prefix.
Tuhin PaulRank #7 · 71.9K reputationPosted Apr 3, 2023, 2:30 PM EDT
You can also set the
modifiedSubjectvalue as the subject line of the email when sending the email using your email client or library.