如何仅使用“ @ sendgrid / mail”启用“沙盒”模式
向“ @ sendgrid / mail”添加“沙盒”模式的计划如何?
同时可以使用沙箱吗?
谢谢!
如上所述,可以以沙盒模式发送,但在用例中未明确显示。 您要发送的邮件正文中的字段之一是mailSettings.sandboxMode.enable
。 将此设置为true将以沙盒模式发送电子邮件。
例如:
import * as SendGrid from '@sendgrid/mail';
import { MailData } from '@sendgrid/helpers/classes/mail';
import { Email } from '../models';
import config from '../config';
export function send(email: Email): Promise<any> {
SendGrid.setApiKey(config.services.email.apiKey);
const mailSettings = config.services.email.options;
const data: MailData = {
...email,
...mailSettings
};
// This will send the email in sandbox mode
data.mailSettings.sandboxMode.enable = true;
return SendGrid.send(data);
}
启用沙盒模式后,电子邮件是否会显示在仪表板上?
@ victor-ponce,
我不这么认为。
对于V3,以下是代码段
const sgMail = require('@ sendgrid / mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
到:“收件人@ example.org ”,
来自:“ [email protected] ”,
主题:“ Hello world”,
文字:“你好平原世界!”,
html:“ Hello HTML world!”,
templateId:'d-f43daeeaef504760851f727007e0b5d0',
dynamic_template_data:{
主题:“测试模板”,
名称:“某人”,
城市:“丹佛”,
},
mail_settings:{
启用:true
}
},
};
sgMail.send(msg);
这不可能吗? 我当前的sendgrid文件如下所示
import sgMail from '@sendgrid/mail';
const sendGridApiKey = process.env.SENDGRID_API_KEY;
if (!sendGridApiKey) {
throw new Error('The sendgrid api key has not been set in the environment variables');
}
sgMail.setApiKey(sendGridApiKey);
// I need to be able to do something like this
sgMail.enableSandbox(process.env.NODE_ENV !== 'production')
export { sgMail };
如果最终sendgrid允许您生成沙箱api密钥(类似于条纹测试密钥),那将是很好的
PR合并以将其添加到文档中。
@malimccalla目前不支持。 由于它与原始请求不太相同,您可以打开一个新期刊来跟踪此问题吗?
@ childish-sambino完成! #1128
最有用的评论
嗨@CrazyGentleMan ,
抱歉,似乎我们在这里没有使用该用例。 它应该在
mail_settings
。 这是完整的有效负载供参考。我已将此添加到我们的积压中。
为了使此问题在我们的积压订单中得到优先考虑,我们需要其他+1或PR。 当我们收到PR时,将提供最大的优先级提升。
谢谢!
最诚挚的问候,
埃尔默