Image 1 of 1

SendGrid

Product information

By Vendure Open Source

Send transactional emails using Twilio Sendgrid with Vendure’s EmailPlugin

npm install @vendure/email-plugin
Support languages
en
Integration type
Core
Category
Email
Compatible with
^3.0.0
Latest version
3.0.0
Last published
Jul 17, 2024
Downloads in past month
13,009

Installation

The Vendure EmailPlugin is usually installed by default, but if you don’t have it in your project follow the installation instructions to install and configure the plugin in your project.

Next, install the @sendgrid/mail package:

npm install @sendgrid/mail

Create an EmailSender

Next you need to create a custom EmailSender class which uses Sendgrid:

// src/config/sendgrid-email-sender.ts
import { EmailSender, EmailDetails } from '@vendure/email-plugin';
const sgMail = require('@sendgrid/mail');

sgMail.setApiKey(process.env.SENDGRID_API_KEY);

class SendgridEmailSender implements EmailSender {
  async send(email: EmailDetails) {
    await sgMail.send({
      to: email.recipient,
      from: email.from,
      subject: email.subject,
      html: email.body,
    });
  }
}

Configure the EmailPlugin

The final step is to configure the EmailPlugin to use this custom sender:

// src/vendure-config.ts
import { VendureConfig } from '@vendure/core';
import { defaultEmailHandlers, EmailPlugin } from '@vendure/email-plugin';

import { SendgridEmailSender } from './config/sendgrid-email-sender';

export const config: VendureConfig = {
  // ...
  plugins: [
    EmailPlugin.init({
      // ... 
      // the transport type "none" is used when using a
      // custom EmailSender
      transport: { type: 'none' },
      emailSender: new SendgridEmailSender(),
    }),
  ],
};
Vendure
Get started

Create your first commerce experience with Vendure in less than 2 minutes

Vendure is a registered trademark. Our trademark policy ensures that our brand and products are protected. Feel free to reach out if you have any questions about our trademarks.

Newsletter

Get the latest product news and announcements delivered directly to your inbox.

© Copyright 2022 - 2024, Vendure GmbH. All rights reserved.