我試圖從Firebase雲端函數使用Mailgun的api發送電子郵件。我曾嘗試在Cloud Function中實現同樣的nodejs教程,但我總是得到「錯誤:無法處理請求」。請問我做錯了什麼。從角色2應用程序的Firebase雲端函數發送mailgun電子郵件
雲功能如下代碼:
<pre>
<code>
var functions = require('firebase-functions');
var nodemailer = require('nodemailer');
var auth = {
auth: {
api_key: '###################',
domain: 's###############g'
}
}
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
var nodemailerMailgun = nodemailer.createTransport(auth);
exports.sendEmail = functions.https.onRequest((request, response) =>{
//app.get('/', function(req, res) {
test();
});
function test(){
const mailOptions = {
//Specify email data
from: "[email protected]",
//The email to contact
to: "[email protected]",
//Subject and text data
subject: 'Hello from Mailgun',
text: 'Hello, This is not a plain-text email, I wanted to test some spicy Mailgun sauce in NodeJS! <a href="http://0.0.0.0:3030/validate?' + req.params.mail + '">Click here to add your email address to a mailing list</a>'
};
return smtpTransport.sendMail(mailOptions).then(() => {
console.log("It works");
});
}
</pre>
感謝您的幫助。
感謝編輯@AL –
你在火力地堡的付費訂閱的一個? Firebase只允許在付費計劃中使用非Google出站網絡請求。 –
@GokulKathirvel。還沒。這可能是問題嗎? –