Reputation: 1
I want to download an entire inbox (email body text and attachments) from my Gmail. Using message IDs, I can get Gmail.Message
objects, but these only appear to contain snippets (about 200 characters).
For C#, is there a way to get the whole inbox in XML format using the Gmail API?
Upvotes: 0
Views: 2170
Reputation: 61
Looking at the API you would need to make a request to /users/me/threads
then to users/me/threads/<id>
within that response there is a body.data
value that is base 64 encoded. I am not 100% sure with the c# API but i assume that you would do something like:
var request = service.Users.Threads.List("me");
var labels = request.Execute().Threads;
foreach(var thread in lables){
var threadReqeust = service.Users.Threads.Get("me", thread.Id);
var data = threadReqeust.Execute();
//you have your entire message now
}
(do take note that this is semi pusudo code, as i have not checked this with the gmail api)
(https://developers.google.com/gmail/api/v1/reference/users/threads/list) (https://developers.google.com/gmail/api/v1/reference/users/threads/get) "An attachment ID is present if the body data is contained in a separate attachment."
Another option is to always login with IMAP (using ImapX or equivalent), and collect data that way, but using the API would be better.
Upvotes: 1
Reputation: 10400
According to the documentation, you can use
GET https://www.googleapis.com/gmail/v1/users/userId/messages/id
Is this the call you are using? It says the default format is Full
:
"full": Returns the full email message data with body content parsed in the payload field; the raw field is not used. (default)
For getting attachments you can try Users.messages.attachments :
GET https://www.googleapis.com/gmail/v1/users/userId/messages/messageId/attachments/id
But for this you will need the attachment ID. You may want to check the User.messages overview, which shows the available data, maybe you can try the Payload
calls?
Upvotes: 0
Reputation: 5141
For gmail API please refer to https://developers.google.com/gmail/api/v1/reference/users/messages/list#parameters
HTTP request
GET https://www.googleapis.com/gmail/v1/users/userId/messages
Make sure you are applying correct authorization headers on your requests.
Upvotes: 0