【问题标题】:Send Email with Firebase Functions and Amazon SES使用 Firebase 函数和 Amazon SES 发送电子邮件
【发布时间】:2021-06-19 03:13:19
【问题描述】:

我只想通过 Firebase Functions 和 AWS 简单电子邮件服务 (SES) 从经过验证的域和经过验证的电子邮件地址(仍在沙箱中)发送一封电子邮件来测试连接。因此,我安装了 node-ses 并创建了以下代码。我将 vuejs 用于 webapp 和 nodejs。

// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');

// The Firebase Admin SDK to access Firestore.
const admin = require('firebase-admin');
admin.initializeApp();

// AWS Credentials
var ses = require('node-ses'), 
    client = ses.createClient({
        key: '...', 
        secret: '...',
        amazon: 'https://email-smtp.eu-west-3.amazonaws.com'
});

exports.scheduledFunction = functions.pubsub.schedule('every 10 minutes').onRun((context) => {

// Give SES the details and let it construct the message for you.
client.sendEmail({
    to: 'support@myVerfiedDomain.com'
  , from: 'do_not_reply@myVerfiedDomain.com'
  //, cc: 'theWickedWitch@nerds.net'
  //, bcc: ['canAlsoBe@nArray.com', 'forrealz@.org']
  , subject: 'Test'
  , message: 'Test Message'
  , altText: 'Whatever'
 }, function (err, data, res) {
  console.log(err)
  console.log(data)
  console.log(res)
 })
})

问题是,我什至无法部署这个功能:每次我得到相同的错误信息:

...
+  functions: created scheduler job firebase-schedule-scheduledFunction-us-central1
+  functions[scheduledFunction(us-central1)]: Successful upsert schedule operation. 

Functions deploy had errors with the following functions:
        scheduledFunction(us-central1)

To try redeploying those functions, run:
    firebase deploy --only "functions:scheduledFunction"

To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.

但如果我部署一个简单的 Firebase 函数,它就可以工作。所以这与我的设置无关。

有人知道我做错了什么吗?

谢谢!! 克里斯

【问题讨论】:

    标签: node.js google-cloud-functions amazon-ses massmail


    【解决方案1】:

    我找到了解决方案。我仍然不知道它如何与node-ses 一起使用,但我知道它如何与nodemailer 一起使用。

    1. 安装nodemailer (npm i nodemailer)
    2. 安装 nodemailer-ses-transport
    3. 将区域更改为适合您设置的区域
    4. 在您的 Firebase Functions 的 index.js 中输入以下内容(输入您的 AWS 凭证)

    --- 下面是源代码 ---

    // The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers. 
    const functions = require('firebase-functions');
    
    // The Firebase Admin SDK to access Firestore. 
    const admin = require('firebase-admin');
    admin.initializeApp();
    
    // Nodemailer 
    var nodemailer = require('nodemailer');
    var ses = require('nodemailer-ses-transport');
        
    // Create transporter
    var transporter = nodemailer.createTransport(ses({
        accessKeyId: '...',
        secretAccessKey: '...',
        region: 'eu-west-3'
    }));
    
    exports.sendEmail = functions.pubsub.schedule('every 1 minutes').onRun((context) => {
        transporter.sendMail({
            from: 'sender@yourVerifiedDomain.com',
            to: 'receiver@yourVerifiedDomain.com',
            subject: 'Email Testing',
            html: '<h1>Title</h1>',
                /*
                attachments: [
                    {
                    filename: 'report',
                    path: 'C:\\xampp\\htdocs\\js\\report.xlsx',
                    contentType: 'application/vnd.ms-excel'
                    }
                ]
                */
        },
        function(err, data) {
            if (err) throw err;
            console.log('Email sent:');
            console.log(data);
        }); 
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 2016-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      相关资源
      最近更新 更多