Skip to content

Instantly share code, notes, and snippets.

@YamimakiReru
Last active December 13, 2023 13:43
Show Gist options
  • Save YamimakiReru/52745c0632af8c680aea3114c7ad0f93 to your computer and use it in GitHub Desktop.
Save YamimakiReru/52745c0632af8c680aea3114c7ad0f93 to your computer and use it in GitHub Desktop.
GAS Webアプリ: POSTリクエストで受け取ったEメールデータをGmailで送り付けるスクリプト
/**
* GAS Webアプリ
* POSTリクエストで受け取ったEメールデータをGmailで送り付けるスクリプト
*
* 使用例:
* curl -L https://script.google.com/macros/s/[デプロイID]/exec -F "to=foo@example.com" -F "subject=はろー" -F "body=はろー"
*
* レスポンス例:
* {"status":"success","body":"正常にメールを送信しました"}
*
* * * *
*
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* Version 2, December 2004
*
* Copyright (C) 2023 YAMIMAKI, Reru
*
* Everyone is permitted to copy and distribute verbatim or modified
* copies of this license document, and changing it is allowed as long
* as the name is changed.
*
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
*
* 0. You just DO WHAT THE FUCK YOU WANT TO.
*/
function doPost(evt) {
try {
const recipient = evt.parameter.to;
const subject = evt.parameter.subject;
const body = evt.parameter.body;
GmailApp.sendEmail(recipient, subject, body);
return returnAsJson('success', '正常にEメールを送信しました');
} catch(ex) {
return returnAsJson('failure',
`${ex.name}: ${ex.message}\n${ex.stack}`);
}
}
function returnAsJson(status, body) {
return ContentService.createTextOutput(
JSON.stringify({status, body}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment