4
votes

I am trying to send a mail using gmail API with POSTMAN, using POST Method

POST https://www.googleapis.com/upload/gmail/v1/users/[email protected]/messages/send

but I get an error below:

{
    "error": {
        "errors": [
            {
                "domain": "global",
                "reason": "invalidArgument"
                "message": "Recipient address required"
            }
        ],
        "code": 400,
        "message": "Recipient address required"
    }
}

header is already putted Content-type: message/rfc822

I know that this has to be encoded into base64(web_safe), so I translated

"From: [email protected]\r\n" +
"To: [email protected]\r\n" +
"Subject: Subject Example\r\n" +
"This is content: hope you got it\r\n"

I also replaced them to be web_safe

 replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); 

so I got an base64 like below. so I put raw in body of POST METHOD

{
    "raw": "RnJvbTogc2VuZGVyLmV4YW1wbGVAZ21haWwuY29tDQpUbzogcmVjZWl2ZXIuZXhhbXBsZUBnbWFpbC5jb20NClN1YmplY3Q6IFN1YmplY3QgRXhhbXBsZQ0KVGhpcyBpcyBjb250ZW50OiBob3BlIHlvdSBnb3QgaXQNCg"
}

I used 'try this api' on google developers' site, and I could send it. https://developers.google.com/gmail/api/v1/reference/users/messages/send

But with POSTMAN, I cannot.

Any help please?

4
Hiya, This link should help ! stackoverflow.com/questions/24460422/…Wilfred Clement
Thanks @WilfredClement , but not really. Cause I think I already satisfy all the conditions. Do you have any idea?Taewon Lee

4 Answers

1
votes

This mean, data format is incorrect. You should try below method which perfectly worked for me.

I use below format.

From: <[email protected]>
To: <[email protected]>
Subject: Test Email

Test

For testing purpose, I used https://ostermiller.org/calc/encode.html to 64encode above text message. So I will get encoded string as below

IEZyb206IDxGUk9NQGdtYWlsLmNvbT4KICAgIFRvOiA8VE9AZ21haWwuY29tPgogICAgU3ViamVjdDogVGVzdCBFbWFpbAogICAgCiAgICBUZXN0

Now in postman,

Gmail Rest API URL you have to use https://www.googleapis.com/gmail/v1/users/<[email protected]>/messages/send

Content type should be json because you send json format in message body.

Content-Type: application/json

In body

{
    "raw": "IEZyb206IDxGUk9NQGdtYWlsLmNvbT4KICAgIFRvOiA8VE9AZ21haWwuY29tPgogICAgU3ViamVjdDogVGVzdCBFbWFpbAogICAgCiAgICBUZXN0"
}

So finally postman looks like as below.

enter image description here

enter image description here

Once you send a request to API, You will receive response looks like this

{
    "id": "172016110a227c19",
    "threadId": "172016110a227c19",
    "labelIds": [
        "UNREAD",
        "SENT",
        "INBOX"
    ]
}
0
votes

I think that you should set the Content-type header to application/json. Also, don't forget to add the Authorization header.

0
votes
0
votes

https://stackoverflow.com/a/61507172/2131809

If you want more details please refer below link: Gmail API send message without using Base64 encode