EmailSender

EmailSender

EmailSender

An EmailSender is responsible for sending the email, e.g. via an SMTP connection or using some other mail-sending API. By default, the EmailPlugin uses the NodemailerEmailSender, but it is also possible to supply a custom implementation:

Example

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

const config: VendureConfig = {
  logger: new DefaultLogger({ level: LogLevel.Debug })
  // ...
  plugins: [
    EmailPlugin.init({
       // ... template, handlers config omitted
      transport: { type: 'none' },
       emailSender: new SendgridEmailSender(),
    }),
  ],
};

Signature

interface EmailSender {
  send: (email: EmailDetails, options: EmailTransportOptions) => void | Promise<void>;
}

Members

send

property
type:
(email: EmailDetails, options: EmailTransportOptions) => void | Promise<void>

NodemailerEmailSender

Uses the configured transport to send the generated email.

Signature

class NodemailerEmailSender implements EmailSender {
  async send(email: EmailDetails, options: EmailTransportOptions) => ;
}

Implements

Members

send

async method
type:
(email: EmailDetails, options: EmailTransportOptions) =>