2

I am currently developing a gmail addon. The addon sends an email, with an attached eml file, to a particular recipient. Unfortunately, the recipient is not able to open the eml file attached with the email I sent via GMAIL API. If they click on the attached eml file they will receive the message "An error occurred while loading the attached message."

enter image description here

I found two issues, which might be related to this issue, when I analyzed the data I saw when I clicked "show original" on the email. One is that all emails I sent via GMAIL API have the "Received from xxxxxxxxxxx named unknown by gmailapi.google.com with HTTPREST" header. And that the entire base64-encoded eml file is missing in the content of the email. Please see image below :

enter image description here

Is this related to Emails sent via GMAIL API are flagged as Phishy? Or am I missing or doing something wrong? If I set the "attachment-type" to "text/plain" then the base64-encoded eml file data is present and viewable when I "show original" the email. Thank you all in advance.

GovZ
  • 253
  • 1
  • 11
  • Do no worry about "Received from xxxxxxxxxxx named unknown by gmailapi.google.com with HTTPREST" for messages sent with Gmail API, this does not affect the readibility of the message. As for your encoding: Is your file base64-encoded or base64ur-encoded? – ziganotschka Jan 09 '20 at 15:29
  • Thank you @ziganotschka it is base64Encoded only. Do i need to use base64URLEncoded()?? thanks. – GovZ Jan 09 '20 at 16:01
  • Yes, it needs to be base64URLEncoded, see here: https://developers.google.com/gmail/api/v1/reference/users/messages/send#request-body – ziganotschka Jan 09 '20 at 16:08
  • 1
    I will try that too. But why does it work correctly if i set the eml-attachment content type as "text/plain" instead of "message/rfc822"? And, if i download the eml attachment sent with content-type="message/rfc822", the downloaded eml file is viewable perfectly in outlook. Another confusing case is the missing eml file content when i "show original". But if i set the attachment content-type to "text/plain" i can see the entire data when i "show original". If this were a simple case of encoding, downloading the eml file will not work too right? or am i mistaken? thanks. – GovZ Jan 09 '20 at 16:46
  • I am not familiar with eml files, but Gmail requires RFC 2822 formatting. Mind that RFC 2822 supersedes RFC 822 (or in other words: RFC 822 is outdated). https://tools.ietf.org/html/rfc2822 – ziganotschka Jan 10 '20 at 08:37
  • @ziganotschka thanks for the assist. I have tried the base64urlencoded() and even simplified the raw data but it did not work. An ".eml" file type is how one would save an email content, like when you download an email from gmail, it gets saved as an "eml" file. If the "named unknown by gmailapi.gmail.com" is a phishing flag by google, it might make sense that eml file attachments are not shown by gmail when this line is present as it is a probable phishing attempt. Do you know a way to contact gmail? Thanks – GovZ Jan 14 '20 at 08:28

1 Answers1

1

@GovZ you can use MailApp.send rather than GmailApp.send, along with setting the content-type to "message/rfc822" and the email should preview correctly.

Details here: https://issuetracker.google.com/issues/155736170

  • Thanks for the answer .. i will take a look into this. Thank you again. – GovZ May 20 '20 at 03:51
  • I apologize for not being able to answer this. I was able to use the MailApp API and successfully send the email and was able to view the attached eml file. The issue however is that it looked like it got sent by this domain "maestro.bounces.google.com" . Moreover, this bug is still not fixed until now. – GovZ Jan 18 '21 at 12:43