带有SendGrid和Firebase的跨国电子邮件,没有错误,但没有电子邮件(使用NodeMailer作为答案)

问题描述 投票:1回答:2

好,所以我用联系表单设置了一个Ionic Webapp,并且表单与Firebase进行了交互,这意味着我的所有表单信息都存储在实时数据库中。现在我已经根据本教程设置了SendGrid:

Firestore-数据库触发的事件;https://fireship.io/lessons/sendgrid-transactional-email-guide/

但是输入新数据时未触发云功能。我在控制台上没有收到任何错误,并且从sendgrid仪表板没有任何请求。我的理解是,当数据库中发生更改时,它将自动触发该功能,然后sendgrid将发送包含相关数据的电子邮件。

这是我的代码;

// Firebase Config
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();

// Sendgrid Config
import * as sgMail from '@sendgrid/mail';

const API_KEY = functions.config().sendgrid.key;
const TEMPLATE_ID = functions.config().sendgrid.template;
sgMail.setApiKey(API_KEY);

// Emails the author when a new messages is added
export const newMessage = functions.firestore.document('messages/{messageId}').onCreate( async (change, context) => {

    // Raw Data
    // const post = postSnap.data();
    const msgData = change.data();

    // Email
    const msg = {
        to: msgData.email,
        from: '[email protected]',
        templateId: TEMPLATE_ID,
        dynamic_template_data: {
            subject: 'New Message',
            name: msgData.name,
            text: `Here is the message: ${msgData.message}`,
            phone: msgData.phone
        },
    };

    // Send it
    return sgMail.send(msg);

});

将功能成功部署到Firebase。

请提供任何帮助。

编辑//////////////////////////////////////////////// /编辑

最终改为使用Nodemailer。

javascript firebase firebase-realtime-database google-cloud-functions sendgrid
2个回答
2
投票

这是免费的Firebase Spark计划https://firebase.google.com/pricing。云功能:出站网络=仅Google服务。如果您更改为Blaze计划,并且不使用太多出站网络,则仍然不会支付任何费用。我有2个月的Blaze计划,三个月不付钱。


0
投票

好的,这就是经过搜索后对我有用的东西。感谢@Mises为我提供了遵循的指导。对于其他尝试使用nodemailer使用firebase发送事务电子邮件的人,这是我的方法。

  1. 我遵循了@Mises给我的上述链接;https://github.com/firebase/functions-samples/tree/Node-8/email-confirmation

我能够将功能上传到Firebase,但是在Firebase功能日志中仍然出现错误;

-发送电子邮件时出错:{错误:丢失“ PLAIN”的凭据]

于是我从那里开始跟随该链接;Missing credentials for "PLAIN" nodemailer

很遗憾,在Google上激活安全性较低的应用对我不起作用。

这里来自nodemailer的官方文档;

https://nodemailer.com/about/

希望这对其他人有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.