const functions = require('firebase-functions');
var nodemailer = require('nodemailer');
// const express=require('express');
var transporter=nodemailer.createTransport('smtps://username@gmail.com:password5@smtp.gmail.com');
exports.sendMail=functions.https.onRequest((req,res)=>{
var mailOptions={
to: 'receiver@gmail.com',
subject: 'Test Mail',
html: 'Testing with Node.js'
}
transporter.sendMail(mailOptions,function(err,response){
if(err){
res.send('Mail not sent');
}
else{
res.send('Mail sent');
}
});
});
我从Firebase应用发送邮件。我根据Sending email using Firebase web app中提出的问题使用Firebase云功能发送邮件。上面的代码是我的index.js文件。
这是我的package.json文件
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1",
"sendgrid": "^5.2.3"
},
"private": true
}
答案 0 :(得分:6)
您从依赖项中遗漏了nodemailer
。只需添加它......
npm install nodemailer --save
将导致(x.x.x
是适当的版本)
"dependencies": {
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1",
"nodemailer": "^x.x.x",
"sendgrid": "^5.2.3"
}
这很可能适用于您的开发,因为您实际上已在本地或全局安装nodemailer
,但由于错误指出,它在远程计算机上不存在
无法找到模块' nodemailer'