使用SmtpClient发送邮件作为回复 [英] Send a mail as a reply using SmtpClient

查看:283
本文介绍了使用SmtpClient发送邮件作为回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:需要发送一封邮件,实际上是来自asp.net c#程序的回复邮件。我管理了要发送到客户端的邮件,但它以新邮件的形式发送。

Scenario : Need to send a mail which is actually a reply mail from an asp.net c# program. I managed the mail to be sent to the client, but it sends as a new mail.

代码:

var SMTP = _genRepository.GetData("SELECT * FROM LOCATION WHERE ID='" + mail.LocationId + "'").FirstOrDefault();
SmtpClient c = new SmtpClient(SMTP.SMTP_Host, SMTP.SMTP_Port);
MailAddress add = new MailAddress(mail.From);
MailMessage msg = new MailMessage();
msg.To.Add(add);
msg.From = new MailAddress(SMTP.Email);
msg.IsBodyHtml = true;
msg.Subject = mail.Subject;
msg.Body = mail.Body;
c.Credentials = new System.Net.NetworkCredential(SMTP.Email, SMTP.EmailPassword);
c.EnableSsl = true;
c.Send(msg);

我有发件人的电子邮件messageid。我只需要知道如何发送邮件作为答复。

I have the sender's email messageid. I just need to know how to send the mail as a reply.

推荐答案

如果添加以下标头,则邮件客户端会考虑

If you add following headers, the mail client would consider the mail as a reply.


In-Reply-To

In-Reply-To

参考


        MailMessage mailMessage = new MailMessage();
        mailMessage.Headers.Add("In-Reply-To", "<Message-ID Value>");
        mailMessage.Headers.Add("References", "<Message-ID Value>");

我找不到SMTP标头的任何官方参考,但以下内容给出了一些详细信息

I could not find any 'official' reference for the SMTP headers, but the following gives some details:


In-Reply-To和 References标头的存在指示该消息是对先前消息的答复。

The presence of In-Reply-To and References headers indicate that the message is a reply to a previous message.

References标头使线程邮件读取成为可能。

The References header makes "threaded mail reading" and per-discussion archival possible.

此外,某些邮件客户端也希望使用完全相同的主题。请参阅与此相关的 SO post

Also, some mail clients wants the exact same subject as well. Please see this related SO post

在前景中,如果邮件主题相同并且会话视图为该文件夹启用,然后不管上面的标题如何,它将把具有相同主题的所有邮件归为一类。

In outlook, if the the mail subject is same and "conversation view" is enabled for the folder, then irrespective of the above headers, it would group all mails with the same subject together.

您可以使用客户端手动发送回复,并将邮件标题与原始邮件,以查看您的客户端如何添加邮件头。

You can send a reply using your client manually and compare the message headers with the original mail to see how your client is adding the message headers.

这篇关于使用SmtpClient发送邮件作为回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆