Search code examples
emailgoogle-apps-scriptmimegmail-addons

Extracting raw message in Gmail apps-script


In my Gmail-addon, I want to be able to read the raw (MIME) message of the current email.

How can I do that?


Solution

  • You can retrieve the message ID of the current message using e.messageMetadata.messageId at function buildAddOn(e){}. I cannot uderstand about raw (MIME) message in your question. So I propose 2 patterns.

    • If you want the raw data of Byte[], you can retrieve it from message ID using Gmail.Users.Messages.get() of Advanced Google Services as follows.
      • Gmail.Users.Messages.get("me", messageId, {format: "RAW"}).raw
      • If you use this, please enable Gmail App at Advanced Google Services and API console.
    • If you want the raw data of String, you can retrieve it from message ID using GmailApp.getMessageById() as follows.
      • GmailApp.getMessageById(messageId).getRawContent()

    Note :

    • If you use this, please set "https://www.googleapis.com/auth/gmail.addons.execute", "https://mail.google.com/" to the scopes.
      • If other scopes are required to be added, please also add them.

    References :

    If I misunderstand your question, I'm sorry.