PGSolutions SyGED
PGSolutions SyGED

Reputation: 41

GMail API retrieve From, To, etc. from a message?

How I can do to retrieve, from, to, subject, etc. from a message with this code ? Actually I can retrive list of message in a folder (label) but i want to retrieve fron, to, sender, etc. to display in a grid

Private Sub LoadMailGrid(ByVal FolderName As String)

        Dim request As Google.Apis.Gmail.v1.UsersResource.MessagesResource.ListRequest = myGMailService.Users.Messages.List("[email protected]")
        request.Q = "label: " + folderName
        Dim messagesList As ListMessagesResponse = request.Execute()

        Dim SubjectList As List(Of GMailMessageSummary) = New List(Of GMailMessageSummary)
        Dim mail As GMailMessageSummary

        For Each Message In messagesList.Messages
            mail = New GMailMessageSummary
            mail.MessageID = Message.Id
            **mail.From = Message.**
            mail.Subject = "Courriel " + x.ToString
            mail.Received = Today
            SubjectList.Add(mail)
        Next

        grdGMail.DataSource = SubjectList
        grdGMail.DataBind()

    End Sub

Upvotes: 2

Views: 1808

Answers (1)

Eric D
Eric D

Reputation: 7159

List message just returns the message Ids and thread ids, not the full content (since that could be an entire email which could be huge like 25MB). So if you want certain info on all of them then call messages.get() in the loop. If you only want headers like To, From, Subject then you can call messages.get(format=METADATA), or however it looks in the language you're using.

https://developers.google.com/gmail/api/v1/reference/users/messages/get

Upvotes: 2

Related Questions