emailengine-app 2.84.2 → 2.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/.ncurc.js +5 -3
  2. package/.prettierignore +5 -1
  3. package/.prettierrc.js +2 -0
  4. package/.release-please-manifest.json +1 -1
  5. package/CHANGELOG.md +33 -0
  6. package/Dockerfile +6 -0
  7. package/README.md +1 -1
  8. package/bin/emailengine.js +434 -408
  9. package/copy-static-files.sh +39 -14
  10. package/data/google-crawlers.json +1 -1
  11. package/data/public_suffix_list.dat +16562 -0
  12. package/eslint.config.js +81 -99
  13. package/lib/account.js +36 -5
  14. package/lib/api-reference/format.js +4 -3
  15. package/lib/api-routes/account-routes.js +177 -12
  16. package/lib/api-routes/blocklist-routes.js +23 -2
  17. package/lib/api-routes/delivery-test-routes.js +26 -3
  18. package/lib/api-routes/export-routes.js +28 -2
  19. package/lib/api-routes/gateway-routes.js +28 -2
  20. package/lib/api-routes/mailbox-routes.js +41 -2
  21. package/lib/api-routes/message-routes.js +97 -3
  22. package/lib/api-routes/oauth2-app-routes.js +48 -15
  23. package/lib/api-routes/outbox-routes.js +45 -11
  24. package/lib/api-routes/permission-map.js +12 -1
  25. package/lib/api-routes/settings-routes.js +23 -2
  26. package/lib/api-routes/submit-routes.js +336 -309
  27. package/lib/api-routes/template-routes.js +38 -2
  28. package/lib/api-routes/token-routes.js +142 -96
  29. package/lib/api-routes/webhook-route-routes.js +13 -2
  30. package/lib/bounce-detect.js +397 -205
  31. package/lib/consts.js +5 -4
  32. package/lib/email-client/base-client.js +10 -31
  33. package/lib/email-client/gmail-client.js +9 -11
  34. package/lib/email-client/imap/mailbox.js +3 -19
  35. package/lib/email-client/imap/subconnection.js +1 -1
  36. package/lib/email-client/imap-client.js +1 -1
  37. package/lib/email-client/notification-handler.js +1 -2
  38. package/lib/gateway.js +2 -3
  39. package/lib/hapi-request-logger.js +107 -0
  40. package/lib/imapproxy/imap-core/README.md +6 -5
  41. package/lib/mcp/tools.js +37 -8
  42. package/lib/notify-attachments.js +17 -0
  43. package/lib/oauth/outlook-mailbox.js +35 -0
  44. package/lib/oauth/state.js +24 -0
  45. package/lib/oauth2-apps.js +1 -1
  46. package/lib/pbkdf2-phc.js +1 -1
  47. package/lib/schemas.js +1 -1
  48. package/lib/sso.js +1 -1
  49. package/lib/swagger-options.js +1 -1
  50. package/lib/thread-diagnostics.js +46 -0
  51. package/lib/timezones.js +109 -0
  52. package/lib/token-permission-view.js +3 -3
  53. package/lib/tools.js +40 -10
  54. package/lib/totp.js +2 -5
  55. package/lib/translations.js +1 -2
  56. package/lib/ui-routes/account-routes.js +475 -454
  57. package/lib/ui-routes/account-setup.js +99 -0
  58. package/lib/ui-routes/admin-config-routes.js +88 -10
  59. package/lib/ui-routes/admin-entities-routes.js +91 -7
  60. package/lib/ui-routes/auth-routes.js +90 -38
  61. package/lib/ui-routes/internals-routes.js +5 -0
  62. package/lib/ui-routes/oauth-config-routes.js +124 -82
  63. package/lib/ui-routes/route-helpers.js +19 -3
  64. package/lib/ui-routes/tls-config-routes.js +58 -15
  65. package/lib/utils/back-off.js +82 -0
  66. package/lib/utils/murmurhash3.js +66 -0
  67. package/lib/utils/public-suffix.js +122 -0
  68. package/lib/utils/random-id.js +26 -0
  69. package/lib/utils/version.js +74 -0
  70. package/lib/webhook-routing.js +27 -0
  71. package/lib/webhooks.js +41 -6
  72. package/package.json +27 -29
  73. package/sbom.json +7980 -1
  74. package/server.js +634 -441
  75. package/static/licenses.html +181 -1006
  76. package/translations/messages.pot +62 -63
  77. package/views/config/ai.hbs +1 -1
  78. package/views/config/security.hbs +2 -2
  79. package/views/config/service.hbs +3 -0
  80. package/views/internals/index.hbs +8 -0
  81. package/views/partials/webhook_form.hbs +1 -1
  82. package/views/suppression-lists/index.hbs +1 -1
  83. package/workers/api.js +738 -583
  84. package/workers/export.js +1 -1
  85. package/workers/submit.js +1 -1
  86. package/workers/webhooks.js +16 -32
@@ -95,8 +95,312 @@ const idempotencyResponseSchema = Joi.object({
95
95
  .description('Idempotency info, present when an Idempotency-Key header was used')
96
96
  .label('ResponseIdempotency');
97
97
 
98
- async function init(args) {
99
- const { server, call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
98
+ function buildSubmitMessagePayloadSchema(MAX_ATTACHMENT_SIZE) {
99
+ return Joi.object({
100
+ reference: messageReferenceSchema,
101
+
102
+ envelope: Joi.object({
103
+ from: mailboxAddressSchema.allow('').example('sender@example.com'),
104
+ to: Joi.array().items(mailboxAddressSchema.required().example('recipient@example.com')).single().label('SmtpEnvelopeTo')
105
+ })
106
+ .description('An optional object specifying the SMTP envelope used during email transmission')
107
+ .meta({ usage: FIELD_USAGE.messageEnvelope })
108
+ .label('SMTPEnvelope')
109
+ .when('mailMerge', {
110
+ is: Joi.exist().not(false, null),
111
+ then: Joi.forbidden('y')
112
+ }),
113
+
114
+ raw: Joi.string()
115
+ .base64()
116
+ .max(MAX_ATTACHMENT_SIZE)
117
+ .example('TUlNRS1WZXJzaW9uOiAxLjANClN1YmplY3Q6IGhlbGxvIHdvcmxkDQoNCkhlbGxvIQ0K')
118
+ .description('A Base64-encoded email message in RFC 822 format')
119
+ .meta({ usage: FIELD_USAGE.messageRaw })
120
+ .label('RFC822Raw')
121
+ .when('mailMerge', {
122
+ is: Joi.exist().not(false, null),
123
+ then: Joi.forbidden('y')
124
+ }),
125
+
126
+ from: fromAddressSchema,
127
+
128
+ replyTo: Joi.array()
129
+ .items(addressSchema.label('ReplyToAddress'))
130
+ .single()
131
+ .example([{ name: 'From Me', address: 'sender@example.com' }])
132
+ .description('List of Reply-To addresses')
133
+ .label('ReplyTo'),
134
+
135
+ to: Joi.array()
136
+ .items(addressSchema.label('ToAddress'))
137
+ .single()
138
+ .example([{ address: 'recipient@example.com' }])
139
+ .description('List of recipient addresses')
140
+ .label('ToAddressList')
141
+ .when('mailMerge', {
142
+ is: Joi.exist().not(false, null),
143
+ then: Joi.forbidden('y')
144
+ }),
145
+
146
+ cc: Joi.array()
147
+ .items(addressSchema.label('CcAddress'))
148
+ .single()
149
+ .description('List of CC addresses')
150
+ .label('CcAddressList')
151
+ .when('mailMerge', {
152
+ is: Joi.exist().not(false, null),
153
+ then: Joi.forbidden('y')
154
+ }),
155
+
156
+ bcc: Joi.array()
157
+ .items(addressSchema.label('BccAddress'))
158
+ .single()
159
+ .description('List of BCC addresses')
160
+ .label('BccAddressList')
161
+ .when('mailMerge', {
162
+ is: Joi.exist().not(false, null),
163
+ then: Joi.forbidden('y')
164
+ }),
165
+
166
+ subject: templateSchemas.subject,
167
+ text: templateSchemas.text,
168
+ html: templateSchemas.html,
169
+ previewText: templateSchemas.previewText,
170
+
171
+ template: Joi.string().max(256).example('example').description('Stored template ID to load the email content from'),
172
+
173
+ render: Joi.object({
174
+ format: Joi.string()
175
+ .valid('html', 'markdown')
176
+ .default('html')
177
+ .description('Markup language the template is written in')
178
+ .meta({ enumDescriptions: ENUM_DESCRIPTIONS.renderFormat })
179
+ .label('RenderFormat'),
180
+ params: Joi.object()
181
+ .label('RenderValues')
182
+ .example({ firstName: 'Nyan', orderId: '4815' })
183
+ .description('An object of variables for the template renderer')
184
+ })
185
+ .allow(false)
186
+ .description('Template rendering options. Set to `false` to send the template as-is, without rendering it.')
187
+ .when('mailMerge', {
188
+ is: Joi.exist().not(false, null),
189
+ then: Joi.forbidden('y')
190
+ })
191
+ .label('TemplateRender'),
192
+
193
+ mailMerge: Joi.array()
194
+ .items(
195
+ Joi.object({
196
+ to: addressSchema.label('ToAddress').required(),
197
+ messageId: Joi.string().max(996).example('<test123@example.com>').description('Message ID'),
198
+ params: Joi.object()
199
+ .label('RenderValues')
200
+ .example({ firstName: 'Nyan', orderId: '4815' })
201
+ .description('An object of variables for the template renderer'),
202
+ sendAt: Joi.date()
203
+ .iso()
204
+ .example('2021-07-08T07:06:34.336Z')
205
+ .description('Send message at specified time. Overrides message level `sendAt` value.')
206
+ }).label('MailMergeListEntry')
207
+ )
208
+ .min(1)
209
+ .max(MAX_MAIL_MERGE_ENTRIES)
210
+ .description(`Mail merge options. A separate email is generated for each recipient, up to ${MAX_MAIL_MERGE_ENTRIES} per request`)
211
+ .meta({ usage: FIELD_USAGE.mailMerge })
212
+ .label('MailMergeList'),
213
+
214
+ attachments: Joi.array()
215
+ .items(
216
+ Joi.object({
217
+ filename: Joi.string().max(256).example('transparent.gif'),
218
+ content: Joi.string()
219
+ .base64()
220
+ .max(MAX_ATTACHMENT_SIZE)
221
+ .required()
222
+ .example('R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=')
223
+ .description('Base64 formatted attachment file')
224
+ .when('reference', {
225
+ is: Joi.exist().not(false, null),
226
+ then: Joi.forbidden(),
227
+ otherwise: Joi.required()
228
+ }),
229
+
230
+ contentType: Joi.string().lowercase().max(256).example('image/gif'),
231
+ contentDisposition: Joi.string().lowercase().valid('inline', 'attachment').label('AttachmentContentDisposition'),
232
+ cid: Joi.string().max(256).example('unique-image-id@localhost').description('Content-ID value for embedded images'),
233
+ encoding: Joi.string().valid('base64').default('base64').label('AttachmentEncoding'),
234
+
235
+ reference: Joi.string()
236
+ .base64({ paddingRequired: false, urlSafe: true })
237
+ .max(256)
238
+ .allow(false, null)
239
+ .example('AAAAAQAACnAcde')
240
+ .description('References an existing attachment by its ID instead of providing new attachment content')
241
+ .meta({ usage: FIELD_USAGE.attachmentReference })
242
+ .label('AttachmentReference')
243
+ }).label('UploadAttachment')
244
+ )
245
+ .max(MAX_MESSAGE_ATTACHMENTS)
246
+ .description('List of attachments')
247
+ .label('UploadAttachmentList'),
248
+
249
+ messageId: Joi.string().max(996).example('<test123@example.com>').description('Message ID'),
250
+ headers: Joi.object().label('CustomHeaders').description('Custom Headers').unknown().example({
251
+ 'X-My-Custom-Header': 'Custom header value'
252
+ }),
253
+
254
+ trackingEnabled: Joi.boolean().example(false).description('Should EmailEngine track clicks and opens for this message').meta({ swaggerHidden: true }),
255
+
256
+ trackOpens: Joi.boolean().example(false).description('Should EmailEngine track opens for this message'),
257
+ trackClicks: Joi.boolean().example(false).description('Should EmailEngine track clicks for this message'),
258
+
259
+ copy: Joi.boolean()
260
+ .allow(null)
261
+ .example(null)
262
+ .description("If set then either copies the message to the Sent Mail folder or not. If not set then uses the account's default setting")
263
+ .meta({ usage: FIELD_USAGE.messageCopy }),
264
+
265
+ sentMailPath: Joi.string()
266
+ .empty('')
267
+ .max(1024)
268
+ .example('Sent Mail')
269
+ .description("Upload sent message to this folder. By default the account's Sent Mail folder is used."),
270
+
271
+ locale: Joi.string().empty('').max(100).example('fr').description('Optional locale').label('MessageLocale'),
272
+ tz: Joi.string().empty('').max(100).example('Europe/Tallinn').description('Optional timezone'),
273
+
274
+ sendAt: sendAtSchema,
275
+ deliveryAttempts: deliveryAttemptsSchema,
276
+ gateway: gatewaySchema,
277
+
278
+ listId: Joi.string()
279
+ .hostname()
280
+ .example('test-list')
281
+ .description('List ID for Mail Merge. Must use a subdomain name format. Lists are registered ad-hoc, so a new identifier defines a new list.')
282
+ .label('ListID')
283
+ .when('mailMerge', {
284
+ is: Joi.exist().not(false, null),
285
+ then: Joi.optional(),
286
+ otherwise: Joi.forbidden()
287
+ }),
288
+
289
+ dsn: dsnSchema.label('DSN'),
290
+
291
+ baseUrl: Joi.string()
292
+ .trim()
293
+ .empty('')
294
+ .uri({
295
+ scheme: ['http', 'https'],
296
+ allowRelative: false
297
+ })
298
+ .example('https://customer123.myservice.com')
299
+ .description('Optional base URL for trackers. This URL must point to your EmailEngine instance.'),
300
+
301
+ proxy: proxySchema,
302
+ localAddress: localAddressSchema,
303
+
304
+ dryRun: apiBoolean()
305
+ .default(false)
306
+ .description(
307
+ 'If true, then EmailEngine does not send the email and returns an RFC822 formatted email file. Tracking information is not added to the email.'
308
+ )
309
+ .label('Preview')
310
+ })
311
+ .oxor('raw', 'html')
312
+ .oxor('raw', 'text')
313
+ .oxor('raw', 'text')
314
+ .oxor('raw', 'attachments')
315
+ .label('SubmitMessage')
316
+ .example({
317
+ to: [
318
+ {
319
+ name: 'Nyan Cat',
320
+ address: 'nyan.cat@example.com'
321
+ }
322
+ ],
323
+ subject: 'What a wonderful message!',
324
+ text: 'Hello from myself!',
325
+ html: '<p>Hello from myself!</p>',
326
+ attachments: [
327
+ {
328
+ filename: 'transparent.gif',
329
+ content: 'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=',
330
+ contentType: 'image/gif'
331
+ }
332
+ ]
333
+ });
334
+ }
335
+
336
+ function buildSubmitMessageResponseSchema() {
337
+ return Joi.object({
338
+ response: Joi.string().example('Queued for delivery'),
339
+ messageId: Joi.string()
340
+ .example('<a2184d08-a470-fec6-a493-fa211a3756e9@example.com>')
341
+ .description('Message-ID header value. Not present for bulk messages.'),
342
+ queueId: Joi.string().example('d41f0423195f271f').description('Queue identifier for scheduled email. Not present for bulk messages.'),
343
+ sendAt: Joi.date().example('2021-07-08T07:06:34.336Z').description('Scheduled send time'),
344
+
345
+ reference: Joi.object({
346
+ message: Joi.string()
347
+ .base64({ paddingRequired: false, urlSafe: true })
348
+ .max(256)
349
+ .example('AAAAAQAACnA')
350
+ .description('Referenced message ID. Not present when only a thread ID was referenced'),
351
+ threadId: threadIdSchema.description('Referenced thread ID (Gmail API accounts only)').label('SubmitResponseReferenceThreadId'),
352
+ success: Joi.boolean().example(true).description('Was the referenced message processed successfully').label('ResponseReferenceSuccess'),
353
+ error: Joi.string().example('Referenced message was not found').description('An error message if referenced message processing failed')
354
+ })
355
+ .description('Reference info if referencing was requested')
356
+ .label('ResponseReference'),
357
+
358
+ preview: Joi.string()
359
+ .base64()
360
+ .example('Q29udGVudC1UeXBlOiBtdWx0aX...')
361
+ .description('Base64 encoded RFC822 email if a preview was requested. Not returned for mail-merge submissions.')
362
+ .label('ResponsePreview'),
363
+
364
+ idempotency: idempotencyResponseSchema,
365
+
366
+ mailMerge: Joi.array()
367
+ .items(
368
+ Joi.object({
369
+ success: Joi.boolean().example(true).description('Was the message queued successfully').label('ResponseReferenceSuccess'),
370
+ to: addressSchema.label('ToAddressSingle'),
371
+ messageId: Joi.string().max(996).example('<test123@example.com>').description('Message ID'),
372
+ queueId: Joi.string().example('d41f0423195f271f').description('Queue identifier for the scheduled email'),
373
+ sendAt: Joi.date().iso().example('2021-07-08T07:06:34.336Z').description('Scheduled send time for this recipient'),
374
+ error: Joi.string().example('Failed to queue message').description('Error message if queueing failed for this recipient'),
375
+ code: Joi.string().example('EENVELOPE').description('Error code if queueing failed for this recipient'),
376
+ statusCode: Joi.number().integer().allow(null).example(500).description('Error status code if queueing failed for this recipient'),
377
+ skipped: Joi.object({
378
+ reason: Joi.string().example('unsubscribe').description('Why this message was skipped'),
379
+ listId: Joi.string().example('test-list')
380
+ })
381
+ .description('Info about skipped message. If this value is set, then the message was not sent')
382
+ .label('SkippedMessageInfo')
383
+ })
384
+ .label('BulkResponseEntry')
385
+ .example({
386
+ success: true,
387
+ to: {
388
+ name: 'Andris 2',
389
+ address: 'andris@ethereal.email'
390
+ },
391
+ messageId: '<19b9c433-d428-f6d8-1d00-d666ebcadfc4@ekiri.ee>',
392
+ queueId: '1812477338914c8372a',
393
+ sendAt: '2021-07-08T07:06:34.336Z'
394
+ })
395
+ .unknown()
396
+ )
397
+ .label('BulkResponseList')
398
+ .description('Bulk message responses')
399
+ }).label('SubmitMessageResponse');
400
+ }
401
+
402
+ function registerSubmitMessage(server, args) {
403
+ const { call, CORS_CONFIG, MAX_ATTACHMENT_SIZE, MAX_BODY_SIZE, MAX_PAYLOAD_TIMEOUT } = args;
100
404
 
101
405
  server.route({
102
406
  method: 'POST',
@@ -223,320 +527,19 @@ async function init(args) {
223
527
 
224
528
  headers: submitHeadersSchema,
225
529
 
226
- payload: Joi.object({
227
- reference: messageReferenceSchema,
228
-
229
- envelope: Joi.object({
230
- from: mailboxAddressSchema.allow('').example('sender@example.com'),
231
- to: Joi.array().items(mailboxAddressSchema.required().example('recipient@example.com')).single().label('SmtpEnvelopeTo')
232
- })
233
- .description('An optional object specifying the SMTP envelope used during email transmission')
234
- .meta({ usage: FIELD_USAGE.messageEnvelope })
235
- .label('SMTPEnvelope')
236
- .when('mailMerge', {
237
- is: Joi.exist().not(false, null),
238
- then: Joi.forbidden('y')
239
- }),
240
-
241
- raw: Joi.string()
242
- .base64()
243
- .max(MAX_ATTACHMENT_SIZE)
244
- .example('TUlNRS1WZXJzaW9uOiAxLjANClN1YmplY3Q6IGhlbGxvIHdvcmxkDQoNCkhlbGxvIQ0K')
245
- .description('A Base64-encoded email message in RFC 822 format')
246
- .meta({ usage: FIELD_USAGE.messageRaw })
247
- .label('RFC822Raw')
248
- .when('mailMerge', {
249
- is: Joi.exist().not(false, null),
250
- then: Joi.forbidden('y')
251
- }),
252
-
253
- from: fromAddressSchema,
254
-
255
- replyTo: Joi.array()
256
- .items(addressSchema.label('ReplyToAddress'))
257
- .single()
258
- .example([{ name: 'From Me', address: 'sender@example.com' }])
259
- .description('List of Reply-To addresses')
260
- .label('ReplyTo'),
261
-
262
- to: Joi.array()
263
- .items(addressSchema.label('ToAddress'))
264
- .single()
265
- .example([{ address: 'recipient@example.com' }])
266
- .description('List of recipient addresses')
267
- .label('ToAddressList')
268
- .when('mailMerge', {
269
- is: Joi.exist().not(false, null),
270
- then: Joi.forbidden('y')
271
- }),
272
-
273
- cc: Joi.array()
274
- .items(addressSchema.label('CcAddress'))
275
- .single()
276
- .description('List of CC addresses')
277
- .label('CcAddressList')
278
- .when('mailMerge', {
279
- is: Joi.exist().not(false, null),
280
- then: Joi.forbidden('y')
281
- }),
282
-
283
- bcc: Joi.array()
284
- .items(addressSchema.label('BccAddress'))
285
- .single()
286
- .description('List of BCC addresses')
287
- .label('BccAddressList')
288
- .when('mailMerge', {
289
- is: Joi.exist().not(false, null),
290
- then: Joi.forbidden('y')
291
- }),
292
-
293
- subject: templateSchemas.subject,
294
- text: templateSchemas.text,
295
- html: templateSchemas.html,
296
- previewText: templateSchemas.previewText,
297
-
298
- template: Joi.string().max(256).example('example').description('Stored template ID to load the email content from'),
299
-
300
- render: Joi.object({
301
- format: Joi.string()
302
- .valid('html', 'markdown')
303
- .default('html')
304
- .description('Markup language the template is written in')
305
- .meta({ enumDescriptions: ENUM_DESCRIPTIONS.renderFormat })
306
- .label('RenderFormat'),
307
- params: Joi.object()
308
- .label('RenderValues')
309
- .example({ firstName: 'Nyan', orderId: '4815' })
310
- .description('An object of variables for the template renderer')
311
- })
312
- .allow(false)
313
- .description('Template rendering options. Set to `false` to send the template as-is, without rendering it.')
314
- .when('mailMerge', {
315
- is: Joi.exist().not(false, null),
316
- then: Joi.forbidden('y')
317
- })
318
- .label('TemplateRender'),
319
-
320
- mailMerge: Joi.array()
321
- .items(
322
- Joi.object({
323
- to: addressSchema.label('ToAddress').required(),
324
- messageId: Joi.string().max(996).example('<test123@example.com>').description('Message ID'),
325
- params: Joi.object()
326
- .label('RenderValues')
327
- .example({ firstName: 'Nyan', orderId: '4815' })
328
- .description('An object of variables for the template renderer'),
329
- sendAt: Joi.date()
330
- .iso()
331
- .example('2021-07-08T07:06:34.336Z')
332
- .description('Send message at specified time. Overrides message level `sendAt` value.')
333
- }).label('MailMergeListEntry')
334
- )
335
- .min(1)
336
- .max(MAX_MAIL_MERGE_ENTRIES)
337
- .description(`Mail merge options. A separate email is generated for each recipient, up to ${MAX_MAIL_MERGE_ENTRIES} per request`)
338
- .meta({ usage: FIELD_USAGE.mailMerge })
339
- .label('MailMergeList'),
340
-
341
- attachments: Joi.array()
342
- .items(
343
- Joi.object({
344
- filename: Joi.string().max(256).example('transparent.gif'),
345
- content: Joi.string()
346
- .base64()
347
- .max(MAX_ATTACHMENT_SIZE)
348
- .required()
349
- .example('R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=')
350
- .description('Base64 formatted attachment file')
351
- .when('reference', {
352
- is: Joi.exist().not(false, null),
353
- then: Joi.forbidden(),
354
- otherwise: Joi.required()
355
- }),
356
-
357
- contentType: Joi.string().lowercase().max(256).example('image/gif'),
358
- contentDisposition: Joi.string().lowercase().valid('inline', 'attachment').label('AttachmentContentDisposition'),
359
- cid: Joi.string().max(256).example('unique-image-id@localhost').description('Content-ID value for embedded images'),
360
- encoding: Joi.string().valid('base64').default('base64').label('AttachmentEncoding'),
361
-
362
- reference: Joi.string()
363
- .base64({ paddingRequired: false, urlSafe: true })
364
- .max(256)
365
- .allow(false, null)
366
- .example('AAAAAQAACnAcde')
367
- .description('References an existing attachment by its ID instead of providing new attachment content')
368
- .meta({ usage: FIELD_USAGE.attachmentReference })
369
- .label('AttachmentReference')
370
- }).label('UploadAttachment')
371
- )
372
- .max(MAX_MESSAGE_ATTACHMENTS)
373
- .description('List of attachments')
374
- .label('UploadAttachmentList'),
375
-
376
- messageId: Joi.string().max(996).example('<test123@example.com>').description('Message ID'),
377
- headers: Joi.object().label('CustomHeaders').description('Custom Headers').unknown().example({
378
- 'X-My-Custom-Header': 'Custom header value'
379
- }),
380
-
381
- trackingEnabled: Joi.boolean()
382
- .example(false)
383
- .description('Should EmailEngine track clicks and opens for this message')
384
- .meta({ swaggerHidden: true }),
385
-
386
- trackOpens: Joi.boolean().example(false).description('Should EmailEngine track opens for this message'),
387
- trackClicks: Joi.boolean().example(false).description('Should EmailEngine track clicks for this message'),
388
-
389
- copy: Joi.boolean()
390
- .allow(null)
391
- .example(null)
392
- .description("If set then either copies the message to the Sent Mail folder or not. If not set then uses the account's default setting")
393
- .meta({ usage: FIELD_USAGE.messageCopy }),
394
-
395
- sentMailPath: Joi.string()
396
- .empty('')
397
- .max(1024)
398
- .example('Sent Mail')
399
- .description("Upload sent message to this folder. By default the account's Sent Mail folder is used."),
400
-
401
- locale: Joi.string().empty('').max(100).example('fr').description('Optional locale').label('MessageLocale'),
402
- tz: Joi.string().empty('').max(100).example('Europe/Tallinn').description('Optional timezone'),
403
-
404
- sendAt: sendAtSchema,
405
- deliveryAttempts: deliveryAttemptsSchema,
406
- gateway: gatewaySchema,
407
-
408
- listId: Joi.string()
409
- .hostname()
410
- .example('test-list')
411
- .description(
412
- 'List ID for Mail Merge. Must use a subdomain name format. Lists are registered ad-hoc, so a new identifier defines a new list.'
413
- )
414
- .label('ListID')
415
- .when('mailMerge', {
416
- is: Joi.exist().not(false, null),
417
- then: Joi.optional(),
418
- otherwise: Joi.forbidden()
419
- }),
420
-
421
- dsn: dsnSchema.label('DSN'),
422
-
423
- baseUrl: Joi.string()
424
- .trim()
425
- .empty('')
426
- .uri({
427
- scheme: ['http', 'https'],
428
- allowRelative: false
429
- })
430
- .example('https://customer123.myservice.com')
431
- .description('Optional base URL for trackers. This URL must point to your EmailEngine instance.'),
432
-
433
- proxy: proxySchema,
434
- localAddress: localAddressSchema,
435
-
436
- dryRun: apiBoolean()
437
- .default(false)
438
- .description(
439
- 'If true, then EmailEngine does not send the email and returns an RFC822 formatted email file. Tracking information is not added to the email.'
440
- )
441
- .label('Preview')
442
- })
443
- .oxor('raw', 'html')
444
- .oxor('raw', 'text')
445
- .oxor('raw', 'text')
446
- .oxor('raw', 'attachments')
447
- .label('SubmitMessage')
448
- .example({
449
- to: [
450
- {
451
- name: 'Nyan Cat',
452
- address: 'nyan.cat@example.com'
453
- }
454
- ],
455
- subject: 'What a wonderful message!',
456
- text: 'Hello from myself!',
457
- html: '<p>Hello from myself!</p>',
458
- attachments: [
459
- {
460
- filename: 'transparent.gif',
461
- content: 'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=',
462
- contentType: 'image/gif'
463
- }
464
- ]
465
- })
530
+ payload: buildSubmitMessagePayloadSchema(MAX_ATTACHMENT_SIZE)
466
531
  },
467
532
 
468
533
  response: {
469
- schema: Joi.object({
470
- response: Joi.string().example('Queued for delivery'),
471
- messageId: Joi.string()
472
- .example('<a2184d08-a470-fec6-a493-fa211a3756e9@example.com>')
473
- .description('Message-ID header value. Not present for bulk messages.'),
474
- queueId: Joi.string().example('d41f0423195f271f').description('Queue identifier for scheduled email. Not present for bulk messages.'),
475
- sendAt: Joi.date().example('2021-07-08T07:06:34.336Z').description('Scheduled send time'),
476
-
477
- reference: Joi.object({
478
- message: Joi.string()
479
- .base64({ paddingRequired: false, urlSafe: true })
480
- .max(256)
481
- .example('AAAAAQAACnA')
482
- .description('Referenced message ID. Not present when only a thread ID was referenced'),
483
- threadId: threadIdSchema.description('Referenced thread ID (Gmail API accounts only)').label('SubmitResponseReferenceThreadId'),
484
- success: Joi.boolean().example(true).description('Was the referenced message processed successfully').label('ResponseReferenceSuccess'),
485
- error: Joi.string().example('Referenced message was not found').description('An error message if referenced message processing failed')
486
- })
487
- .description('Reference info if referencing was requested')
488
- .label('ResponseReference'),
489
-
490
- preview: Joi.string()
491
- .base64()
492
- .example('Q29udGVudC1UeXBlOiBtdWx0aX...')
493
- .description('Base64 encoded RFC822 email if a preview was requested. Not returned for mail-merge submissions.')
494
- .label('ResponsePreview'),
495
-
496
- idempotency: idempotencyResponseSchema,
497
-
498
- mailMerge: Joi.array()
499
- .items(
500
- Joi.object({
501
- success: Joi.boolean().example(true).description('Was the message queued successfully').label('ResponseReferenceSuccess'),
502
- to: addressSchema.label('ToAddressSingle'),
503
- messageId: Joi.string().max(996).example('<test123@example.com>').description('Message ID'),
504
- queueId: Joi.string().example('d41f0423195f271f').description('Queue identifier for the scheduled email'),
505
- sendAt: Joi.date().iso().example('2021-07-08T07:06:34.336Z').description('Scheduled send time for this recipient'),
506
- error: Joi.string().example('Failed to queue message').description('Error message if queueing failed for this recipient'),
507
- code: Joi.string().example('EENVELOPE').description('Error code if queueing failed for this recipient'),
508
- statusCode: Joi.number()
509
- .integer()
510
- .allow(null)
511
- .example(500)
512
- .description('Error status code if queueing failed for this recipient'),
513
- skipped: Joi.object({
514
- reason: Joi.string().example('unsubscribe').description('Why this message was skipped'),
515
- listId: Joi.string().example('test-list')
516
- })
517
- .description('Info about skipped message. If this value is set, then the message was not sent')
518
- .label('SkippedMessageInfo')
519
- })
520
- .label('BulkResponseEntry')
521
- .example({
522
- success: true,
523
- to: {
524
- name: 'Andris 2',
525
- address: 'andris@ethereal.email'
526
- },
527
- messageId: '<19b9c433-d428-f6d8-1d00-d666ebcadfc4@ekiri.ee>',
528
- queueId: '1812477338914c8372a',
529
- sendAt: '2021-07-08T07:06:34.336Z'
530
- })
531
- .unknown()
532
- )
533
- .label('BulkResponseList')
534
- .description('Bulk message responses')
535
- }).label('SubmitMessageResponse'),
534
+ schema: buildSubmitMessageResponseSchema(),
536
535
  failAction: 'log'
537
536
  }
538
537
  }
539
538
  });
539
+ }
540
+
541
+ function registerSubmitDraft(server, args) {
542
+ const { call, CORS_CONFIG } = args;
540
543
 
541
544
  server.route({
542
545
  method: 'POST',
@@ -573,6 +576,23 @@ async function init(args) {
573
576
  tags: ['api', 'Submit'],
574
577
 
575
578
  plugins: {
579
+ mcp: {
580
+ name: 'send_draft',
581
+ title: 'Send draft',
582
+ description:
583
+ 'Send a draft that is already stored in the account, by its message id - confirm with the user before calling this. ' +
584
+ 'This is the second half of a review workflow: create_draft stores the message in the Drafts folder and returns its id, the user looks it over (get_message reads it back), ' +
585
+ 'and send_draft then sends that same draft as it is. The draft carries its own recipients, subject and content, so nothing else is needed. ' +
586
+ 'The message has to be a draft: in the Drafts folder or flagged \\Draft. Once sent it is removed from Drafts and, unless the account is set not to keep copies, filed in Sent. ' +
587
+ 'Delivery is queued; the response carries the queue id for get_outbox.',
588
+ // The draft and nothing else. Every field of the payload is an override of a
589
+ // decision the operator made when connecting the account (the SMTP envelope,
590
+ // the gateway, DSN, whether and where the sent copy is filed, how often
591
+ // delivery is retried) or a network override (`proxy`, `localAddress`). An
592
+ // allowlist for the reason send_message keeps one: a field added to the route
593
+ // later must not join the agent-facing schema by default.
594
+ keep: ['account', 'message']
595
+ },
576
596
  openapi: {
577
597
  'x-ee-impact': IMPACT.SENDS,
578
598
  'x-ee-behavior': [BEHAVIOR.QUEUED_DELIVERY, BEHAVIOR.SENT_FOLDER_UPLOAD],
@@ -681,4 +701,11 @@ async function init(args) {
681
701
  });
682
702
  }
683
703
 
704
+ async function init(args) {
705
+ const { server } = args;
706
+
707
+ registerSubmitMessage(server, args);
708
+ registerSubmitDraft(server, args);
709
+ }
710
+
684
711
  module.exports = init;