Reputation: 10112
I am building an extension for Chrome browser. I wish to be able to parse the content of (the currently viewed) email message in Gmail (and some other email clients, such as Hotmail, Yahoo, etc.). I browsed through Stackoverflow and Google's developer guide, but I could not find how it should be done.
If one could provide a small toy example of how to read the the content of the email (i.e. having a variable which holds the email text\HTML content) it would be great.
thanks.
Upvotes: 3
Views: 4440
Reputation: 1
Better way which I think is to get ids as per your requirement and use GMail APIs to access other details. For example, I've a requirement of all reciepients of the current open thread so accessing the id of the thread and using Gmail APIs. You can get the thread id by using the following code.
var currentThreadId = document.querySelector("[data-inboxsdk-currentthreadid]").getAttribute('data-inboxsdk-currentthreadid');
var legacyThreadId = document.querySelector("[data-thread-perm-id='"+currentThreadId+"']").getAttribute('data-legacy-thread-id');
legacyThreadId will work for APIs.
Upvotes: 0
Reputation: 566
Each email has its own message Id which is unique.
Use content.js
to fetch the "messageId" from the elements and then pass it to Gmail API
to fetch the email data.
Sample:
<div class="adn ads" style="display:" data-message-id="189******56e***3" data-legacy-message-id="189******56e***3">
The API returns the data of the email in various format. One of those is the "raw" format which returns the full email body as a base64url encoded string. Send this data as it is to your server and then decrypt the email and save it to your database.
Please refer the similar question: "Get gmail message body of an open mail with a chrome extension"
Upvotes: 0
Reputation: 2469
You should check out the APIs here, https://github.com/joscha/gmailr, it should get you started.
Edit: There's another newly released unofficial API (still updated) at https://github.com/KartikTalwar/gmail.js
Upvotes: 6
Reputation: 5706
Have a look at Content Scripts... By using the standard Document Object Model (DOM), they can read details of the web pages the browser visits
Upvotes: 1