它返回正确数量的消息,但是填充的唯一字段是Id和ThreadId。其他一切都是空的
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
ListMessagesResponse response = service.Users.Messages.List(emailAddress).Execute();
IList<Google.Apis.Gmail.v1.Data.Message> messages = response.Messages;
Console.WriteLine("Messages:");
if (messages != null && messages.Count > 0)
{
foreach (var message in messages)
{
Console.WriteLine("{0}", message.Payload.Body);
Console.WriteLine();
}
}
else
{
Console.WriteLine("No Messages found.");
}
答案 0 :(得分:7)
Messages.List()仅返回消息和线程ID。要检索邮件内容,您需要为您感兴趣的每条邮件调用Get()。foreach
循环示例的更新版本:
foreach (var message in messages)
{
Message m = service.Users.Messages.Get("me", message.Id).Execute();
// m.Payload is populated now.
foreach (var part in message.Payload.Parts)
{
byte[] data = Convert.FromBase64String(part.Body.Data);
string decodedString = Encoding.UTF8.GetString(data);
Console.WriteLine(decodedString);
}
}