GMAIL REST API - sending email with attachments
Application Type
Traditional Web

Hi everyone,

    I'm trying to use the gmail api, currently i was able to consume the method for sending an email without an attachment, but when it comes to attaching a file i couldn't make it work, i cannot consume it, i'm trying to use the upload type multipart, but i always end up having an error of "Malformed multipart body".

here's the request i am sending:



POST - 

https://www.googleapis.com/upload/gmail/v1/users/userId/messages/send?uploadType=multipart

Authorization: Bearer + AccessToken

Content-Type : multipart/related; boundary=foo_bar_baz


--foo_bar_baz

Content-Type: application/json; charset=utf-8

Content-Disposition: form-data; name="metadata"

{"raw":"RnJvbTo8bGF1cmVuY2UuZGVvY2FtcG9AdGRndHJhdmVsLnBoPgpUbzogPGxhdXJlbmNlLmRlb2NhbXBvQGdtYWlsLmNvbT4KU3ViamVjdDogTmV3ZXN0IEVtYWlsIFBhcnRzCkNvbnRlbnQtVHlwZTogdGV4dC9odG1sOyBjaGFyc2V0PXV0Zi04OwoKCjxwPjxzdHJvbmc+TG9yZW0gSXBzdW08c3BhbiBzdHlsZT0iZm9udC1mYW1pbHk6THVjaWRhIFNhbnMgVW5pY29kZSxMdWNpZGEgR3JhbmRlLHNhbnMtc2VyaWYiPjxzcGFuIHN0eWxlPSJjb2xvcjojMjk4MGI5Ij48ZW0+Jm5ic3A7aXMgc2ltcGx5IGR1bW15IHRleHQgb2YgdGhlIHByaW50aW5nIGFuZCB0eXBlc2V0dGluZyBpbmR1c3RyeS4gTG9yZW0gSXBzdW0gaGFzIGJlZW4gdGhlIGluZHVzdHJ5JiMzOTtzIDwvZW0+PC9zcGFuPjwvc3Bhbj48L3N0cm9uZz48L3A+"}

--foo_bar_baz

Content-Type: image/png

Content-Transfer-Encoding: BASE64

Content-Description: Picture B

Content-Disposition: ATTACHMENT

[base64-encoded image] - i will not attached it here since it's too long.

--foo_bar_baz--


Anybody who had a previous experience in using the gmail api? any suggestions, i was a bit stuck up with this. any suggestions will do.


Thanks.


-Renz

mvp_badge
MVP

You might want to check the multipart/form-data Forge component. It can produce correct output.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.