1
votes

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.

1
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
Thank you @ziganotschka it is base64Encoded only. Do i need to use base64URLEncoded()?? thanks.GovZ
Yes, it needs to be base64URLEncoded, see here: developers.google.com/gmail/api/v1/reference/users/messages/…ziganotschka
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
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). tools.ietf.org/html/rfc2822ziganotschka

1 Answers

1
votes

@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