【发布时间】:2012-03-18 16:02:52
【问题描述】:
我开发了一个 Web 应用程序,其中有一个功能可以为特定的销售订单输入备注。
当客户或客户服务主管输入注释时,将向相关方发送电子邮件通知(电子邮件通知使用 C# 中的 SmtpClient 和 MailMessage 对象发送)。
using (MailMessage objEmail = new MailMessage())
{
Guid objGuid = new Guid();
objGuid = Guid.NewGuid();
String MessageID = "<" + objGuid.ToString() + ">";
objEmail.Body = messagebody.ToString();
objEmail.From = new MailAddress(sFrmadd, sFrmname);
objEmail.Headers.Add("Message-Id", MessageID);
objEmail.IsBodyHtml = true;
objEmail.ReplyTo = new MailAddress("replyto@email.com");
objEmail.Subject = sSubject;
objEmail.To.Add(new MailAddress(sToadd));
SmtpClient objSmtp = new SmtpClient();
objSmtp.Credentials = new NetworkCredential("mynetworkcredential", "mypassword");
objSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
objSmtp.EnableSsl = true;
objSmtp.Host = "myhostname";
objSmtp.Port = 25;
objSmtp.Timeout = 3 * 3600;
objSmtp.Send(objEmail);
}
我将Guid 设置为邮件标头中正在发送的邮件的Message-Id。
这一切都很好。
现在我想开发一个功能,让各方从各自的收件箱回复电子邮件通知。
并且我想在备注中记录对同一销售订单(相关方收到通知)的回复。
我正在使用 OpenPop.dll 来阅读收件箱中的通知回复。
/// <summary>
/// Fetch all messages from a POP3 server
/// </summary>
/// <param name="hostname">Hostname of the server. For example: pop3.live.com</param>
/// <param name="port">Host port to connect to. Normally: 110 for plain POP3, 995 for SSL POP3</param>
/// <param name="useSsl">Whether or not to use SSL to connect to server</param>
/// <param name="username">Username of the user on the server</param>
/// <param name="password">Password of the user on the server</param>
/// <returns>All Messages on the POP3 server</returns>
public static List<Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password)
{
// The client disconnects from the server when being disposed
using (Pop3Client client = new Pop3Client())
{
// Connect to the server
client.Connect(hostname, port, useSsl);
// Authenticate ourselves towards the server
client.Authenticate(username, password);
// Get the number of messages in the inbox
int messageCount = client.GetMessageCount();
// We want to download all messages
List<Message> allMessages = new List<Message>(messageCount);
// Messages are numbered in the interval: [1, messageCount]
// Ergo: message numbers are 1-based.
for (int i = 1; i <= messageCount; i++)
{
allMessages.Add(client.GetMessage(i));
}
// Now return the fetched messages
return allMessages;
}
}
通过上述功能,我可以阅读“replyto@email.com”帐户中的所有电子邮件。但我无法在电子邮件的In-reply-to 标头中找到Message-Id。
我不知道我做错了什么。
【问题讨论】:
-
据我所知,没有可靠的方法可以做到这一点,您受制于电子邮件客户端,每个电子邮件客户端都有自己的怪癖。我见过的大多数类似系统都使用 主题行 来放入唯一的 id,然后在回复消息时从头开始删除“RE:”。
-
我们过去常常在电子邮件中添加一些自定义标题。
-
我相信即使是 Outlook 的对话也是基于主题的。