Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable sandbox #612

Closed
SimoMay opened this issue Nov 8, 2017 · 10 comments · Fixed by #850
Closed

How to enable sandbox #612

SimoMay opened this issue Nov 8, 2017 · 10 comments · Fixed by #850
Labels
difficulty: easy fix is easy in difficulty status: help wanted requesting help from the community type: docs update documentation change not affecting the code

Comments

@SimoMay
Copy link

SimoMay commented Nov 8, 2017

Issue Summary

How to enable "sandbox" mode, using only "@sendgrid/mail"

Technical details:

  • @sendgrid/mail: 6.1.4
  • Node.js Version: 8.9.0
@thinkingserious thinkingserious added status: help wanted requesting help from the community type: question question directed at the library labels Nov 10, 2017
@thinkingserious
Copy link
Contributor

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

@thinkingserious thinkingserious added difficulty: easy fix is easy in difficulty up-for-grabs type: docs update documentation change not affecting the code and removed type: question question directed at the library labels Mar 5, 2018
@acaua
Copy link

acaua commented Aug 14, 2018

How is the plan to add "sandbox" mode to "@sendgrid/mail" going?

Is there an alternative to use sandbox meanwhile?

Thanks!

@notdmart
Copy link
Contributor

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);
}

@vicpon
Copy link

vicpon commented Aug 28, 2018

Does the email show up in the dashboard when sandbox mode is enabled?

@thinkingserious
Copy link
Contributor

@victor-ponce,

I don't think so.

@notdmart
Copy link
Contributor

#850 to add this documentation

@ferarnoled
Copy link

ferarnoled commented Feb 1, 2019

For V3 here's the snippet

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'recipient@example.org',
  from: 'sender@example.org',
  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);

@malimccalla
Copy link

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

@childish-sambino
Copy link
Contributor

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?

@malimccalla
Copy link

@childish-sambino Done! #1128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: easy fix is easy in difficulty status: help wanted requesting help from the community type: docs update documentation change not affecting the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants