How to retrieve my Gmail messages using Gmail API?

后端 未结 5 1085
忘掉有多难
忘掉有多难 2020-12-14 04:35

What I want to achieve:


I\'m using the Gmail API and basically I would like to connect to my GMail account to read my emails, of INBOX categ

5条回答
  •  半阙折子戏
    2020-12-14 05:09

    The user parameter in GoogleWebAuthorizationBroker.AuthorizeAsync is just used by FileDatastore to store your credentials check my tutorial Google .net – FileDatastore demystified for more information.

    My VB.net is very rusty like 6 years rusty but in C# you could do something like this

    UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List("Users email address");
    var response = request.Execute();
    
    foreach (var item in response.Messages) {
         Console.WriteLine(item.Payload.Headers);            
     }
    

    MessageResource.ListRequest returns a list of message objects you can loop though them.

    Users.Messages contains header which should have the subject and the to and from.

    I also have a really old C# tutorial on gmail that might help.

    Update to answer your update:

    What happens when you remove:

    .LabelIds = New Repeatable(Of String)({folder.Id})
    

    labelIds string Only return messages with labels that match all of the specified label IDs.

    It appears you are sending a folder id. try using user.lables.list which returns Lists all labels in the user's mailbox

提交回复
热议问题