はじめに
- 新型コロナウイルス対策でテレワークが急速に普及している。
- 出退勤時にメールを送る運用をしているところがあるらしい。
- しかし、テンプレメールを毎日送るのは面倒くさい。
- GASを使ってワンクリックでメールを送れるようにしたので紹介する。
作ったもの
- ボタンを押すと(ほぼ)固定文言のメールを送ることができるWebページ

- 送られるメール(内容は適当)

#ソースコード
コード.gs
function doGet() {
const toppage = HtmlService.createTemplateFromFile("home");
return toppage.evaluate();
}
function doPost(postdata){
const button = postdata.parameters.button.toString();
const to = 'hoge@gmail.com';
const subject = button + 'します';
const body = button + 'します';
GmailApp.sendEmail(to, subject, body)
const resultpage = HtmlService.createTemplateFromFile("home");
return resultpage.evaluate();
}
home.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1>出退勤メール</h1>
<form method="post" action="https://script.google.com/macros/s/hogehoge/exec">
<input type="submit" name="button" value="出勤">
<input type="submit" name="button" value="退勤">
</form>
</body>
</html>
- URLはアプリごとに変わるため、書き換える必要がある。
- ツールバーの「公開」→「ウェブアプリケーションとして導入...」を選択
- Current web app URLに記載されているURLをコピペ


未実装内容
- 送信先情報をスプレットシートから読み込むようにしたい。
- ボタンの判定が雑すぎるので良い感じにしたい。
おわりに
- 退屈なことは自動化して楽に仕事がしたい。