5

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

POST https://www.googleapis.com/upload/gmail/v1/users/example@gmail.com/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: sender.example@gmail.com\r\n" +
"To: receiver.example@gmail.com\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?

Taewon Lee
  • 61
  • 1
  • 4
  • Hiya, This link should help ! https://stackoverflow.com/questions/24460422/how-to-send-a-message-successfully-using-the-new-gmail-rest-api – Wilfred Clement Aug 29 '18 at 09:11
  • Thanks @WilfredClement , but not really. Cause I think I already satisfy all the conditions. Do you have any idea? – Taewon Lee Aug 30 '18 at 01:30

4 Answers4

1

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

I use below format.

From: <FROM@gmail.com>
To: <TO@gmail.com>
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/<YOUR@gmail.com>/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"
    ]
}
kamprasad
  • 608
  • 4
  • 12
0

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

  • Thank you, but I already did all. if I set content-type to application/json, it doesn't work. it has to be a rfc822. and I added Authorization already. I guess it's just an argument problem. Anyway thanks. – Taewon Lee Sep 05 '18 at 17:02
  • The way i use it: if you want to set content type to rfc822, you dont need to convert the request in Base64url, you just send the formated email in the body of the request. For more examples, check this answer https://stackoverflow.com/questions/24908700/mail-attachment-wrong-media-type-gmail-api – Andrei Vasile Sep 06 '18 at 18:13
  • Hey Thank you! Unbelievable. Cause I also saw this just yesterday!! and I came here to update and you already did! Thank you So much!! Just may I ask you a question? It also says send all the parameters(from, to, subject, ...) without curly brace. is there any way to use curly brace? if I use it, I got bounce... I am using ipaas now, and it provides {} automatically. thanks – Taewon Lee Sep 07 '18 at 23:11
  • I don't think that you can format the headers using {}. Instead, you can format using this format: `To: FirstName LastName
    `
    – Andrei Vasile Sep 10 '18 at 11:56
0

enter image description here

If you want more details please refer below link: How to send a message successfully using the new Gmail REST API?

Ravv
  • 482
  • 4
  • 7
0

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

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

Ravv
  • 482
  • 4
  • 7