What I am doing
I am strictly following the Gmail API guide - https://developers.google.com/gmail/api/guides/sending
https://developers.google.com/gmail/api/reference/rest/v1/users.messages/send
From the sample code given for both sending a simple mail and mail with an attachment. I learned from these codes that we need to send Base64 encoded value as "raw" as per RFC-2822.
Sending mail without attachment
I am able to encode the below RFC 2822 format in Base64 and send mail successfully.
From: automationreportbyamod#gmail.com
To: automationreportbyamod2#gmail.com
Subject: Saying Hello
This is a message just to say hello.
So, "Hello".
Sending mail with attachment
From the example code with the attachment, I see that we need to encode email content with the attachment in Base64. But if we want to do the same using Postman, how can I encode a simple format with a file to be uploaded?
Note - As explained here, I have tried the raw as text and passed the attachment file as Base64 and that is working as well. But I want to make it work as shown in the example code here using Postman.
Related
I've got a webhook which is parsing emails sent by SendGrid's Inbound Parse, and if any error occurs with processing the email, I want to send the original email as an EML attachment to a notification email address.
I've been using Busboy to parse the multipart/form-data received by the webhook and I receive the full plain cleartext of the email contents itself. Everything is fine there.
When I go to send the email using #sendgrid/mail and set the original email as an EML attachment file, this is where I get issues.
I've tried a variety of content encodings and mimetypes, but haven't found one that works yet as a EML file. I've tried text/plain, message/rfc822 and application/octet-stream with plain text (which results in error from SendGrid API), and base64 encoded text.
In fact, it gets weirder. When I send the email attachment as text/plain with filename ending in .txt, everything seems to be good. When I download the attachment and rename to .eml then it views perfectly in my Mail app.
However, when I send the email attachment as text/plain, message/rfc822 or application/octet-stream with filename ending in .eml, this is where I get inconsistencies. In the email I sent I can see that the filename now ends with .eml.eml and opening the file in my Mail app shows me base64 encoded text (decoding the text gives me the original email contents that I had to encode in order to allow the endpoint to send as an attachment). Viewing the file contents in a text editor looks like this:
Content-Type: text/plain
MIME-Version: 1.0
VGhpcyBpcyB3aGVyZSB0aGUgYmFzZTY0IGVuY29kZWQgZW1haWwgdGV4dCBnb2Vz
My current conclusion is that the SendGrid /v3/mail/send API endpoint is treating attachments with .eml extension in the filename differently and encapsulating the base64-encoded contents within another .eml wrapper. It doesn't seem possible to set an attachment's content to a plain text string as I get a 400 Bad Request from the endpoint if its not base64 encoded.
I haven't been able to find any official documentation about this particular behaviour on this endpoint. The closest I got was this GitHub issue (dated 2018), but it doesn't seem to solve my issue.
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."
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 :
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 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
I'm using PHPMailer to send an HTML email when someone requests a brochure from a website.
My issue is that when I send the email without the attachment the email opens and displays the HTML email correctly. As soon as I add the attachment it doesn't load the HTML email and just shows text. NB: I haven't uploaded any code as the email itself sends with or without the attachment, so didn't think you guys would need it.
So:
1) Email sends OK with or without the attachment
2) With the attachment, it arrives (with the attachment) but doesn't show HTML email
3) Without the attachment the HTML is displayed correctly.
This specifically relates to an iPhone and it asks me to download the remainder of the email.
I know this should work OK as I know a competitors website that uses the exact same process and their email loads perfect everytime!
Any help would be useful.
I want to send image, text and bullet point with different colours. I am only able to send back message using
slackClient.sendMessage(botSays(parsedResp, witError, message) , message.channel);
But I don't know how to send attachment. Any help will be appreciable
Thanks
I found the answer. Attachments can be sent to user via IncomingWebhook or Web Api. There are many html text formatting and image attachment also possible. Slack Attachment api
If a user has created a draft in the gmail web UI that contains Unicode characters in the subject, calling Draft.Send seems to not handle these unicode characters correctly.
You can test this by:
Create a draft in gmail with the subject "snowman ☃"
Call drafts.list to get the draft id in the API explorer (https://developers.google.com/gmail/api/v1/reference/users/drafts/list#try-it)
Call Drafts.send using that draft id in the api explorer (https://developers.google.com/gmail/api/v1/reference/users/drafts/send#try-it)
Goto Gmail web ui, then the sent folder, and see that the email was sent with a subject of "snowman: ☃"
Any workarounds for this?
Using NodeJs, here is what I got it working for sending Unicode Characters along with emoji signs. Details in this comment
Email messages can only contain ASCII characters. See RFC 5335. Did you try encoding the subject?
Subject: =?utf-8?b?c25vd21hbiDimIM=?=
You didn't mention what language you're using but most have a library for performing the encoding.