问题
I resolved it and it's quite easy, Gmail has provided a very fine way to do it.
I am writing this article because when I was stuck in this situation there was no answer for it in basic HTTP Request, there were articles for JavaScript, Ruby, etc.., but I read from it and understood the concept,
This article will give a lamen understanding, so you can further implement it in any language.
I am a beginner and if any mistake or further improvement which can be done please inform.
To send a DRAFT
Create a DRAFT with:
URL: POST-https://www.googleapis.com/gmail/v1/users/userId/drafts
Where userId belongs to your email Id
Example: POST-https://www.googleapis.com/gmail/v1/users/example123@gmail.com/drafts
BODY:
{
"message":{
"raw":"Base64 Encoded Value"
}
}
Suppose you want to send Email to example123@gmail.com then String will be: To: example123@gmail.com
Now encode it in base64 format, VG86IGV4YW1wbGUxMjNAZ21haWwuY29t Now your body for the request will be,
BODY:
{
"message":{
"raw": "VG86IGV4YW1wbGUxMjNAZ21haWwuY29t"
}
}
You can do it with any Base64 converter online, I used https://www.base64encode.net/
Now execute it...
When you execute it, You will get Id of the Draft and many other things with it as a Response. For verification of creation of Draft go to your given account and check the increment in the Draft list.
You can get the Response as:
{
"id": string,
"message": users.messages Resource
}
Get that Id of the DRAFT, now time to send it...
To send the created DRAFT do the following things:
- Use the URL: POST https://www.googleapis.com/gmail/v1/users/userId/drafts/send
- Use BODY:
{
"id":"The Id Which you got from the Response when you created the DRAFT"
}
Example if you got Id from the Response as: xyz-2044837380038622546
Then BODY will be as:
{
"id":"xyz-2044837380038622546"
}
If you didn't supply the raw
or forgot it to do it then you can write it while sending the message too...like:
{
"id":"xyz-2044837380038622546",
"message":
{
"raw": "VG86IGV4YW1wbGUxMjNAZ21haWwuY29t"
}
}
And execute the same... Now the Draft which you created will be sent, you can do the same for sending message too, with some modifications...
来源:https://stackoverflow.com/questions/58909602/i-had-some-issues-in-recipient-address-required-error-400-when-working-with-g