9
/emails
に何かが書かれているが、電子メールが送信されず、ファンクションログが空である場合は、電子メールにテスト電子メールを送信しようとしています。Firebaseのクラウド機能 - メールを送信onWrite
exports.sendTestEmail = functions.database.ref('/emails')
.onWrite(event => {
return sendTestEmail('[email protected]');
})
// [END onWrite]
// Sends a welcome email to the given user.
function sendTestEmail(email) {
const mailOptions = {
from: `${APP_NAME} <[email protected]>`,
to: email
};
// The user subscribed to the newsletter.
mailOptions.subject = `Welcome to ${APP_NAME}!`;
mailOptions.text = `Hey there! Welcome to ${APP_NAME}. I hope you will enjoy our service.`;
return mailTransport.sendMail(mailOptions).then(() => {
console.log('New welcome email sent to:', email);
});
}
編集***
上記のコードは動作します。正しい名前がemail
の間に私はemails
の機能をトリガーしようとしていました。
あなたはsmtpサービスとしてGmailを使用していますか?もしそうなら、Googleのセキュリティのために個人パスワードの代わりにアプリパスワードを使用する必要があるかもしれません。これを行う方法は次のとおりです。https://support.google.com/accounts/answer/185833?hl=ja – Tobidae
はい問題は、ユーザーがアカウントを作成するときに同じ形式で電子メールを送信することです。それはうまくいく。 – Ciprian
sendでエラーをキャッチしよう: 'mailTransport.sendMail(mailOptions).then(...)。catch(error => {console.error( 'Error sending:'、エラー);});' –