@@ -13,6 +13,7 @@ import {
13
13
IntermediateEmailDetails ,
14
14
LoadDataFn ,
15
15
SetAttachmentsFn ,
16
+ SetMetadataFn ,
16
17
SetOptionalAddressFieldsFn ,
17
18
SetSubjectFn ,
18
19
SetTemplateVarsFn ,
@@ -140,6 +141,7 @@ export class EmailEventHandler<T extends string = string, Event extends EventWit
140
141
private setTemplateVarsFn : SetTemplateVarsFn < Event > ;
141
142
private setAttachmentsFn ?: SetAttachmentsFn < Event > ;
142
143
private setOptionalAddressFieldsFn ?: SetOptionalAddressFieldsFn < Event > ;
144
+ private setMetadataFn ?: SetMetadataFn < Event > ;
143
145
private filterFns : Array < ( event : Event ) => boolean > = [ ] ;
144
146
private configurations : EmailTemplateConfig [ ] = [ ] ;
145
147
private defaultSubject : string ;
@@ -246,6 +248,17 @@ export class EmailEventHandler<T extends string = string, Event extends EventWit
246
248
return this ;
247
249
}
248
250
251
+ /**
252
+ * @description
253
+ * A function which allows {@link EmailMetadata} to be specified for the email.
254
+ *
255
+ * @since 3.1.0
256
+ */
257
+ setMetadata ( optionalSetMetadataFn : SetMetadataFn < Event > ) {
258
+ this . setMetadataFn = optionalSetMetadataFn ;
259
+ return this ;
260
+ }
261
+
249
262
/**
250
263
* @description
251
264
* Defines one or more files to be attached to the email. An attachment can be specified
@@ -322,6 +335,7 @@ export class EmailEventHandler<T extends string = string, Event extends EventWit
322
335
asyncHandler . setTemplateVarsFn = this . setTemplateVarsFn ;
323
336
asyncHandler . setAttachmentsFn = this . setAttachmentsFn ;
324
337
asyncHandler . setOptionalAddressFieldsFn = this . setOptionalAddressFieldsFn ;
338
+ asyncHandler . setMetadataFn = this . setMetadataFn ;
325
339
asyncHandler . filterFns = this . filterFns ;
326
340
asyncHandler . configurations = this . configurations ;
327
341
asyncHandler . defaultSubject = this . defaultSubject ;
@@ -397,6 +411,8 @@ export class EmailEventHandler<T extends string = string, Event extends EventWit
397
411
}
398
412
const attachments = await serializeAttachments ( attachmentsArray ) ;
399
413
const optionalAddressFields = ( await this . setOptionalAddressFieldsFn ?.( event ) ) ?? { } ;
414
+ const metadata = this . setMetadataFn ? await this . setMetadataFn ( event ) : { } ;
415
+
400
416
return {
401
417
ctx : event . ctx . serialize ( ) ,
402
418
type : this . type ,
@@ -406,6 +422,7 @@ export class EmailEventHandler<T extends string = string, Event extends EventWit
406
422
subject,
407
423
templateFile : configuration ? configuration . templateFile : 'body.hbs' ,
408
424
attachments,
425
+ metadata,
409
426
...optionalAddressFields ,
410
427
} ;
411
428
}
0 commit comments