「@sendgrid / mail」のみを使用して「サンドボックス」モードを有効にする方法
「@sendgrid / mail」に「sandbox」モードを追加する計画はどうなっていますか?
その間にサンドボックスを使用する代替手段はありますか?
ありがとう!
上記のように、サンドボックスモードで送信することは可能ですが、ユースケースでは明示的に示されていません。 送信する内容の本文内のフィールドの1つは、 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 = {
宛先:
差出人:
件名:「Helloworld」、
テキスト:「こんにちはプレーンワールド!」、
html: 'Hello HTML world!'、
templateId: 'd-f43daeeaef504760851f727007e0b5d0'、
dynamic_template_data:{
件名:「テストテンプレート」、
名前: 'Some One'、
市:「デンバー」、
}、
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を受け取るとき、それは優先順位の最大のジャンプを提供します。
ありがとう!
敬具、
エルマー