Finding gmail API url

What is the API url for sending emails via gmail? I can’t seem to find it.

Hi! I have the same problem, someone can help us ?

Hi,

Please follow the instructions of this article. Note that the SendGrid API key, “send from” and “send to” email addresses should be added to the sendEmail function of the email.jsw module. You can simply add your Gmail address to the “sender” variable of the sendEmail function or any other email address that you use so that it will look like you send the email from this email address.

Have a good day,
Tal.

thanks you Tal for your quick anwsers, I always use the code of this article as you can see below.


//'email.jsw
import {sendWithService} from ‘backend/sendGrid’;
export function sendEmail1(subject, body) {
const key = “my_API_key”;
const sender = “my_mail_adress”;
const recipient = “recipient_mail_adress”;
return sendWithService(key, sender, recipient, subject, body);
}

//sendGrid
import {fetch} from ‘wix-fetch’;
export function sendWithService(key, sender, recipient, subject, body) {
const url = “https://www.googleapis.com/gmail/v1/users//messages/send” // <<== ??
const headers = {
“Authorization”: "Bearer " + key,
“Content-Type”: “application/json”
};
const data = from=${sender}&to=${recipient}&subject=${subject}&text=${body};
//console.log(data);
const request = {
“method”: “post”,
“headers”: headers,
“body”: data
};
return fetch(url, request)
.then(response => response.json());
}

I don’t know which url to use, and when I try this code I get the following error :

{“error”:{“errors”:[{“domain”:“global”,“reason”:“authError”,“message”:“Invalid Credentials”,“locationType”:“header”,“location”:“Authorization”}],“code”:401,“message”:“Invalid Credentials”}}

I read (again) the google docs but it will seem that the gmail api doesn’t work with the api key but with OAuth 2.0 . could you confirm ?

Hi bokdany,

I noticed that you’ve used Google’s API address at the sendWithService function (the " url " variable ) instead of using the SendGrid API address. Note that the example mentioned in the article is related to SendGrid API. You can use this API to send Emails from your Gmail address as well . All you need to do, is adding your Gmail address to the " sender " variable:


Moreover, you should register to the SendGrid email delivery service and get an API key so that you can add the generated key to the " key " variable of this function.

I hope it’s clearer now.

Best,
Tal.

thanks Tal, may be I will follow this way.

thanks Tal, may be I will follow this way.

Where do I find my API that goes in this line
const key = “my_API_key”;