Plans to support Sendgrid with mailer?

Hi there!

I’m currently using Resend with mailer to send transactional emails in our app. I am looking at potentially using a different provider for a variety of reasons – a few of which are that Resend had a pretty massive data breach recently and something like SendGrid supports their own templates.

So my question: does RedwoodJS plan on supporting any other email providers? Or is their already a community supported sender that I just haven’t been able to find?

Thanks!

2 Likes

Hey! Yeah we certainly do plan to support more. I suspect we’d be keen to limit the number we maintain ourselves and look for good community handlers to fill in any gap. I’m not aware of any community one either so we’d be happy to explore adding one.

I’ll need to take a more specific look into them. You said you wanted to use their templating? I imagine that might involve an API call in place of rendering a local email template. I believe we support that in principle already.

Okay, yeah let’s take a look at it. If you’d want to contribute some code I’d be more than happy to help out.

1 Like

Sorry for the delay here! I’d be happy to contribute – although I’m a bit wary because I think getting setup to contribute would take 5x actually writing the adapter :sweat_smile: (and I am a team of 1.5 right now)

If there is a path to getting setup quickly, I can help out for sure

Adding here in case there is someone who wants to contribute a new handler, some good references are:

and could follow the Resend handle as a pattern to follow

The key is to map the Sendgrid mail options to the handler (like the categories and the attachments):

const client = require('@sendgrid/mail');

client.setApiKey(process.env.SENDGRID_API_KEY);

const message = {
  personalizations: [
    {
      to: [
        {
          email: 'john_doe@example.com',
          name: 'John Doe'
        },
        {
          email: 'julia_doe@example.com',
          name: 'Julia Doe'
        }
      ],
      cc: [
        {
          email: 'jane_doe@example.com',
          name: 'Jane Doe'
        }
      ],
      bcc: [
        {
          email: 'james_doe@example.com',
          name: 'Jim Doe'
        }
      ]
    },
    {
      from: {
        email: 'sales@example.com',
        name: 'Example Sales Team'
      },
      to: [
        {
          email: 'janice_doe@example.com',
          name: 'Janice Doe'
        }
      ],
      bcc: [
        {
          email: 'jordan_doe@example.com',
          name: 'Jordan Doe'
        }
      ]
    }
  ],
  from: {
    email: 'orders@example.com',
    name: 'Example Order Confirmation'
  },
  replyTo: {
    email: 'customer_service@example.com',
    name: 'Example Customer Service Team'
  },
  subject: 'Your Example Order Confirmation',
  content: [
    {
      type: 'text/html',
      value: '<p>Hello from Twilio SendGrid!</p><p>Sending with the email service trusted by developers and marketers for <strong>time-savings</strong>, <strong>scalability</strong>, and <strong>delivery expertise</strong>.</p><p>%open-track%</p>'
    }
  ],
  attachments: [
    {
      content: 'PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ImVuIj4KCiAgICA8aGVhZD4KICAgICAgICA8bWV0YSBjaGFyc2V0PSJVVEYtOCI+CiAgICAgICAgPG1ldGEgaHR0cC1lcXVpdj0iWC1VQS1Db21wYXRpYmxlIiBjb250ZW50PSJJRT1lZGdlIj4KICAgICAgICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIgY29udGVudD0id2lkdGg9ZGV2aWNlLXdpZHRoLCBpbml0aWFsLXNjYWxlPTEuMCI+CiAgICAgICAgPHRpdGxlPkRvY3VtZW50PC90aXRsZT4KICAgIDwvaGVhZD4KCiAgICA8Ym9keT4KCiAgICA8L2JvZHk+Cgo8L2h0bWw+Cg==',
      filename: 'index.html',
      type: 'text/html',
      disposition: 'attachment'
    }
  ],
  categories: [
    'cake',
    'pie',
    'baking'
  ],
  sendAt: 1617260400,
  batchId: 'AsdFgHjklQweRTYuIopzXcVBNm0aSDfGHjklmZcVbNMqWert1znmOP2asDFjkl',
  asm: {
    groupId: 12345,
    groupsToDisplay: [
      12345
    ]
  },
  ipPoolName: 'transactional email',
  mailSettings: {
    bypassListManagement: {
      enable: false
    },
    footer: {
      enable: false
    },
    sandboxMode: {
      enable: false
    }
  },
  trackingSettings: {
    clickTracking: {
      enable: true,
      enableText: false
    },
    openTracking: {
      enable: true,
      substitutionTag: '%open-track%'
    },
    subscriptionTracking: {
      enable: false
    }
  }
};

client
  .send(message)
  .then(() => console.log('Mail sent successfully'))
  .catch(error => {
    console.error(error);
  });