email-sender.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { InjectableStrategy } from '@vendure/core';
  2. import { EmailDetails, EmailTransportOptions } from './types';
  3. /**
  4. * @description
  5. * An EmailSender is responsible for sending the email, e.g. via an SMTP connection
  6. * or using some other mail-sending API. By default, the EmailPlugin uses the
  7. * {@link NodemailerEmailSender}, but it is also possible to supply a custom implementation:
  8. *
  9. * @example
  10. * ```TypeScript
  11. * const sgMail = require('\@sendgrid/mail');
  12. *
  13. * sgMail.setApiKey(process.env.SENDGRID_API_KEY);
  14. *
  15. * class SendgridEmailSender implements EmailSender {
  16. * async send(email: EmailDetails) {
  17. * await sgMail.send({
  18. * to: email.recipient,
  19. * from: email.from,
  20. * subject: email.subject,
  21. * html: email.body,
  22. * });
  23. * }
  24. * }
  25. *
  26. * const config: VendureConfig = {
  27. * logger: new DefaultLogger({ level: LogLevel.Debug })
  28. * // ...
  29. * plugins: [
  30. * EmailPlugin.init({
  31. * // ... template, handlers config omitted
  32. * transport: { type: 'none' },
  33. * emailSender: new SendgridEmailSender(),
  34. * }),
  35. * ],
  36. * };
  37. * ```
  38. *
  39. * @docsCategory EmailPlugin
  40. * @docsPage EmailSender
  41. * @docsWeight 0
  42. */
  43. export interface EmailSender extends InjectableStrategy {
  44. send: (email: EmailDetails, options: EmailTransportOptions) => void | Promise<void>;
  45. }