如何在C#中使用Gmail API获取Gmail主题

时间:2016-09-02 05:45:48

标签: c# gmail gmail-api

我正在创建一个可以从C#控制台应用程序获取Gmail收件箱中所有电子邮件的应用程序。

我在下面的代码中打印出控制台的电子邮件正文内容:

UsersResource.ThreadsResource.ListRequest threadRequest = service.Users.Threads.List("me");
IList<Google.Apis.Gmail.v1.Data.Thread> threads = threadRequest.Execute().Threads;

foreach(var thread in threads)
{
     //print gmail body content
     Console.WriteLine("{0}", thread.Snippet);
}

那么我如何获得gmail主题呢? 任何贡献都会得到满足!

1 个答案:

答案 0 :(得分:0)

public string GetMail(){
GmailService service = (GmailService)HttpContext.Current.Session["service"];
Message messageFeed = service.Users.Messages.List("me").Execute().Messages.First();
UsersResource.MessagesResource.GetRequest getReq = new UsersResource.MessagesResource.GetRequest(service, "me", messageFeed.Id);
 //"raw": Returns the full email message data with body content in the raw field as a base64url encoded string; the payload field is not used. 
getReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw;
 Message message = getReq.Execute();
return message.Raw;
}

Getting more data from messages.get in C#

Gmail API

更好的解决方案:

Read the Gmail Inbox Feed with .NET and OAuth