Skip to content

Instantly share code, notes, and snippets.

@Kazuki-tam
Last active May 5, 2020 16:12
Show Gist options
  • Save Kazuki-tam/7f89c75717687bfac37228696d8b860a to your computer and use it in GitHub Desktop.
Save Kazuki-tam/7f89c75717687bfac37228696d8b860a to your computer and use it in GitHub Desktop.
/**
* 以下記事を参照
* https://qiita.com/ryo2132/items/7cdd6c86dd418095f74a
*/
const functions = require("firebase-functions");
const nodemailer = require("nodemailer");
const gmailEmail = functions.config().gmail.email;
const gmailPassword = functions.config().gmail.password;
const adminEmail = functions.config().admin.email;
// 送信に使用するメールサーバーの設定
const mailTransport = nodemailer.createTransport({
service: "gmail",
auth: {
user: gmailEmail,
pass: gmailPassword
}
});
// 通知用メールテンプレート
const adminContents = data => {
return `お問い合わせを受けました。
お名前:
${data.name}
メールアドレス:
${data.email}
`;
};
exports.sendMail = functions.https.onCall(async data => {
// メール設定
let adminMail = {
from: gmailEmail,
to: adminEmail,
subject: "お問い合わせ",
text: adminContents(data)
};
// 通知先へのメール送信
try {
await mailTransport.sendMail(adminMail);
} catch (e) {
console.error(`send failed. ${e}`);
throw new https.HttpsError("internal", "send failed");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment