Reputation: 61
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?
Upvotes: 5
Views: 11049
Reputation: 648
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"
}
Once you send a request to API, You will receive response looks like this
{
"id": "172016110a227c19",
"threadId": "172016110a227c19",
"labelIds": [
"UNREAD",
"SENT",
"INBOX"
]
}
Upvotes: 1
Reputation: 482
If you want more details please refer below link: Gmail API send message without using Base64 encode
Upvotes: 0
Reputation: 482
If you want more details please refer below link: How to send a message successfully using the new Gmail REST API?
Upvotes: 0
Reputation: 1
I think that you should set the Content-type
header to application/json
. Also, don't forget to add the Authorization
header.
Upvotes: 0