1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

apiとか使わずにGoogleAppsScript経由でjava script でgmailを送る方法

Last updated at Posted at 2022-02-21

apiとか使わずにapp script経由でjava script でgmailを送る方法です。

具体的にどうなってるのかというと

1.javascriptでget送信でapp scriptを起動

2.app scriptがget送信のクエリを取得してgmailを送る.

appscript側
function doGet(e) {
  let options = e.parameter.name //送信者の名前
  let body = e.parameter.text   //本文
  let subject = e.parameter.subject //送信先の担当者名   
  let recipient = e.parameter.mail             //送信先のメールアドレス

  GmailApp.sendEmail(recipient, subject, body, options);
}

上をまずデプロイします。
そして、urlを取得します。

javascript側
let name = ""; //送信者の名前
let text = "";//本文
let subject = "";//送信先の担当者名 
let mail = ""//送信先のメールアドレス

let send = "https://script.google.com/macros/xxxxxxxxxxxxxx/exec?name=${name}&text=${text}&subject=${subject}&mail=${mail}"  //appscriptのurl
var data_url = new XMLHttpRequest();
data_url.open('GET', send);
data_url.send();

これでapiを使わずにgmailを送れます。

中二が書いたコードなので変なとこがあったら大目にみてください。m_ _m
一応サーバーとかに上げてみてもうまくいきました。

追記:よくよく考えたらセキュリティ的にクソ雑魚でした。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?