foreach (var part in emailInfoResponse.Result.Payload.Parts)
{
if (part.Parts != null)
foreach (var innerPart in part.Parts)
{
if (innerPart.MimeType == "text/plain")
{
body = innerPart.Body.Data;
}
}
}
我正在成功阅读主邮件的正文。它没有从分配给邮件的回复消息中获取数据, 任何想法如何我也可以阅读邮件的回复?或者即使有办法只收取特定邮件的回复
答案 0 :(得分:0)
要在对话中获取更晚/其他消息,您需要检索源线程:
String threadID = emailInfoResponse.Result.ThreadId;
Thread thread = service.Users.Threads.Get(userID, threadID).Execute();
foreach( var msg in thread.Messages )
{
/* your code for each message */
}
根据Gmail message reference,如果消息具有正确的标头和相同的主题,则消息可以共享threadId。否则,它们将位于不同的电子邮件线程中。
你可能想要重构一下,从ThreadList
开始。这样,您可以找到与特定输入查询匹配的所有会话(仅查找与这些客户端列表对应的消息):
Dictionary<String, Container>
,其中字符串是公司(来自电子邮件主题或任何地方),容器可能只需要HashSet
或类似的唯一值。答案 1 :(得分:0)
public static MimeKit.MimeMessage Reply(MimeKit.MimeMessage message, bool replyToAll)
{
var reply = new MimeKit.MimeMessage();
if (message.ReplyTo.Count > 0)
{
reply.To.AddRange(message.ReplyTo);
}
else if (message.From.Count > 0)
{
reply.To.AddRange(message.From);
}
else if (message.Sender != null)
{
reply.To.Add(message.Sender);
}
if (replyToAll)
{
reply.To.AddRange(message.To);
reply.Cc.AddRange(message.Cc);
}
if (!message.Subject.StartsWith("Re:", StringComparison.OrdinalIgnoreCase))
reply.Subject = "Re:" + message.Subject;
else
reply.Subject = message.Subject;
if (!string.IsNullOrEmpty(message.MessageId))
{
reply.InReplyTo = message.MessageId;
foreach (var id in message.References)
reply.References.Add(id);
reply.References.Add(message.MessageId);
}
using (var quoted = new StringWriter())
{
var sender = message.Sender ?? message.From.Mailboxes.FirstOrDefault();
quoted.WriteLine("On {0}, {1} wrote:", message.Date.ToString("f"), !string.IsNullOrEmpty(sender.Name) ? sender.Name : sender.Address);
using (var reader = new StringReader(message.TextBody))
{
string line;
while ((line = reader.ReadLine()) != null)
{
quoted.Write("> ");
quoted.WriteLine(line);
}
}
reply.Body = new MimeKit.TextPart("plain")
{
Text = quoted.ToString()
};
}
return reply;
}