Reputation: 56497
I was unable to find any documented way to accomplish to send email through GMAIL API, using url (GET request), something like this:
https://example_api/?action=send&[email protected]&message=hello&[email protected]&pass=xyz-app-pass
any ideas or tricks to accomplish that ? (so, I could use plain or app password).
Upvotes: 1
Views: 417
Reputation: 201553
I believe your goal as follows.
https://example_api/?action=send&[email protected]&message=hello&[email protected]&pass=xyz-app-pass
using Gmail API.I thought that your goal can be achieved using Web Apps created by Google Apps Script. In this case, the script might be a simple. So in this answer, I would like to propose to achieve your goal using Web Apps created by Google Apps Script.
Please do the following flow.
Sample script of Web Apps is a Google Apps Script. So please create a project of Google Apps Script.
If you want to directly create it, please access to https://script.new/. In this case, if you are not logged in Google, the log in screen is opened. So please log in to Google. By this, the script editor of Google Apps Script is opened.
Please copy and paste the following script (Google Apps Script) to the script editor. This script is for the Web Apps.
function doGet(e) {
const allowedUsers = [
{email: "[email protected]", password: "xyz-app-pass"},
,
,
,
]; // If you want to allow other users to use this script, please add other emails and passwords to the `allowedUsers` array;
const subject = "sample subject";
const {action, to, message, auth_user, pass} = e.parameter;
if (action == "send" && allowedUsers.some(({email, password}) => email == auth_user && password == pass)) {
MailApp.sendEmail({to: to, subject: subject, body: message});
return HtmlService.createHtmlOutput("Email was sent.");
}
return HtmlService.createHtmlOutput("Email was not sent.");
}
{email: "###", password: "###"}
of "User A" to allowedUsers
in the script. By this, only registered users can send the email.Execute the app as: Me
and Who has access to the app: Only myself
.https://script.google.com/macros/s/###/exec
.
Please access to the URL of your Web Apps using your browser by including the query parameters as follows. When you have already been logged in Google, the script of Web Apps is run.
https://script.google.com/macros/s/###/exec?action=send&[email protected]&message=hello&[email protected]&pass=xyz-app-pass
Result:
When above script is run and auth_user
and pass
are included in allowedUsers
, Email was sent.
is returned.
https://www.googleapis.com/auth/drive.file
(in some cases,might work /drive
or /drive.readonly
)Upvotes: 2