How to enable "sandbox" mode, using only "@sendgrid/mail"
Hi @CrazyGentleMan,
My apologies, it seems that we have left out that use case here. It should be within mail_settings
. Here is the complete payload for reference.
I've added this to our backlog.
For this issue to gain priority in our backlog, we need additional +1's or a PR. When we receive a PR, that provides the biggest jump in priority.
Thanks!
With Best Regards,
Elmer
How is the plan to add "sandbox" mode to "@sendgrid/mail" going?
Is there an alternative to use sandbox meanwhile?
Thanks!
As mentioned above, it is possible to send in sandbox mode, but it's not explicitly shown in the use cases. One of the fields within the body of what you're sending is mailSettings.sandboxMode.enable
. Setting this to true will send the email in sandbox mode.
For example:
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);
}
Does the email show up in the dashboard when sandbox mode is enabled?
@victor-ponce,
I don't think so.
For V3 here's the snippet
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: '[email protected]',
from: '[email protected]',
subject: 'Hello world',
text: 'Hello plain world!',
html: 'Hello HTML world!',
templateId: 'd-f43daeeaef504760851f727007e0b5d0',
dynamic_template_data: {
subject: 'Testing Templates',
name: 'Some One',
city: 'Denver',
},
mail_settings: {
sandbox_mode: {
enable: true
}
},
};
sgMail.send(msg);
Is this not possible? My current sendgrid file looks like this
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 };
It would be great if eventually sendgrid allowed you to generate sandbox api keys much like stripe test keys
PR merged to add this to the docs.
@malimccalla That's not currently supported. Since it's not quite the same as the original request, could you open a new issue to track this?
@childish-sambino Done! #1128
Most helpful comment
Hi @CrazyGentleMan,
My apologies, it seems that we have left out that use case here. It should be within
mail_settings
. Here is the complete payload for reference.I've added this to our backlog.
For this issue to gain priority in our backlog, we need additional +1's or a PR. When we receive a PR, that provides the biggest jump in priority.
Thanks!
With Best Regards,
Elmer