javascript - 如何使用我的 svelte firebase + sendgrid 电子邮件功能修复 500 错误
问题描述
我正在开发一个带有用于收集用户电子邮件地址的输入的瘦登陆页面,这样我就可以使用 firebase + sendgrid 自动向他们发送电子邮件。
目前我收到 500 条错误消息:{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
这是我已部署到 firebase 的函数定义:
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
const db = admin.firestore();
// 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);
// Sends email via HTTP. Can be called from frontend code.
export const genericEmail = functions.https.onCall(async (data) => {
const msg = {
to: data.email,
from: 'ghns1133@gmail.com',
templateId: TEMPLATE_ID,
dynamic_template_data: {
subject: data.subject,
name: data.text,
},
};
console.log(msg);
await sgMail.send(msg);
// Handle errors here
// Response must be JSON serializable
// return { success: true };
});
我在我的苗条应用程序中这样称呼它:
const callable = functions.httpsCallable('genericEmail');
return callable({ text: 'Sending email with Svelte and SendGrid is fun!', subject: 'Email from Svelte', email: formInput}).then(console.log);
解决方案
推荐阅读
- python - Pygame 运动的标志和字符与墙壁
- c - 从 IDE 运行 Wine 程序所需的构建命令
- javascript - 在 javascript 数组中添加属性 - 值
- regex - 正则表达式以 3 个连续的大写字母开头
- python - KeyError: 'APP1' 使用 exif 读取元数据时
- django - Django 没有使用 SQLite 为外键创建数据库约束
- python - 删除字符串的特定部分
- email - 是否可以为移动设备指定 MIME 内容类型?
- python - 为什么即使答案是正确的,while 循环也不会在这个函数中中断?
- libgdx - 如何将武器附在玩家手上并实现动态瞄准?