KartikTalwar / gmail.js

Gmail JavaScript API
MIT License
3.74k stars 455 forks source link

Get MIME type #706

Closed GTP95 closed 2 years ago

GTP95 commented 2 years ago

Greetings,

Is there a method get the MIME type of an attachment of a received email? A quick search didn't turn up anything. Thank you fir your help,

GTP

josteink commented 2 years ago

I don't think so. You'll have to map the attachment extension against known mime-types.

There's npm-packages for that though. I just took a quick search and the first thing I found was this:

https://www.npmjs.com/package/mime-types

GTP95 commented 2 years ago

Thanks for your answer. I found an alternative way that I'll report here for future reference, but unfortunately seems that Gmail changes the content-type so I can't rely on it and I have to find a workaround. Anyway to get the content-type:

gmail.observe.on("view_email", (domEmail) => {
    const emailData = gmail.new.get.email_data(domEmail);
    const attachments = emailData.attachments;
    const type=attachment.type   //this gets the MIME type
});