|
|
@@ -63,12 +63,16 @@ export interface EmailPluginOptions {
|
|
|
* @description
|
|
|
* An optional allowed EmailSender, used to allow custom implementations of the send functionality
|
|
|
* while still utilizing the existing emailPlugin functionality.
|
|
|
+ *
|
|
|
+ * @default NodemailerEmailSender
|
|
|
*/
|
|
|
emailSender?: EmailSender;
|
|
|
/**
|
|
|
* @description
|
|
|
* An optional allowed EmailGenerator, used to allow custom email generation functionality to
|
|
|
* better match with custom email sending functionality.
|
|
|
+ *
|
|
|
+ * @default HandlebarsMjmlGenerator
|
|
|
*/
|
|
|
emailGenerator?: EmailGenerator;
|
|
|
}
|
|
|
@@ -234,7 +238,8 @@ export interface FileTransportOptions {
|
|
|
|
|
|
/**
|
|
|
* @description
|
|
|
- * Does nothing with the generated email. Mainly intended for use in testing where we don't care about the email transport.
|
|
|
+ * Does nothing with the generated email. Intended for use in testing where we don't care about the email transport,
|
|
|
+ * or when using a custom {@link EmailSender} which does not require transport options.
|
|
|
*
|
|
|
* @docsCategory EmailPlugin
|
|
|
* @docsPage Transport Options
|
|
|
@@ -274,13 +279,57 @@ export interface TestingTransportOptions {
|
|
|
onSend: (details: EmailDetails) => void;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @description
|
|
|
+ * 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
|
|
|
+ * {@link NodemailerEmailSender}, but it is also possible to supply a custom implementation:
|
|
|
+ *
|
|
|
+ * @example
|
|
|
+ * ```TypeScript
|
|
|
+ * 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(),
|
|
|
+ * }),
|
|
|
+ * ],
|
|
|
+ * };
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * @docsCategory EmailPlugin
|
|
|
+ * @docsPage EmailSender
|
|
|
+ * @docsWeight 0
|
|
|
+ */
|
|
|
export interface EmailSender {
|
|
|
- send: (email: EmailDetails, options: EmailTransportOptions) => void;
|
|
|
+ send: (email: EmailDetails, options: EmailTransportOptions) => void | Promise<void>;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @description
|
|
|
* An EmailGenerator generates the subject and body details of an email.
|
|
|
+ *
|
|
|
+ * @docsCategory EmailPlugin
|
|
|
+ * @docsPage EmailGenerator
|
|
|
+ * @docsWeight 0
|
|
|
*/
|
|
|
export interface EmailGenerator<T extends string = any, E extends VendureEvent = any> {
|
|
|
/**
|
|
|
@@ -307,6 +356,7 @@ export interface EmailGenerator<T extends string = any, E extends VendureEvent =
|
|
|
* A function used to load async data for use by an {@link EmailEventHandler}.
|
|
|
*
|
|
|
* @docsCategory EmailPlugin
|
|
|
+ * @docsPage Email Plugin Types
|
|
|
*/
|
|
|
export type LoadDataFn<Event extends EventWithContext, R> = (context: {
|
|
|
event: Event;
|
|
|
@@ -351,6 +401,7 @@ export class EmailWorkerMessage extends WorkerMessage<IntermediateEmailDetails,
|
|
|
* combination.
|
|
|
*
|
|
|
* @docsCategory EmailPlugin
|
|
|
+ * @docsPage Email Plugin Types
|
|
|
*/
|
|
|
export interface EmailTemplateConfig {
|
|
|
/**
|