使用SmtpClient发送邮件作为回复

编程入门 行业动态 更新时间:2024-10-18 22:32:10
本文介绍了使用SmtpClient发送邮件作为回复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

Scenario : Need to send a mail which is actually a reply mail from an asp 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发送邮件作为回复

本文发布于:2023-11-17 12:20:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609986.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送邮件   SmtpClient

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!