emailengine-app 2.84.1 → 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 (147) hide show
  1. package/.dockerignore +6 -0
  2. package/.ncurc.js +5 -3
  3. package/.prettierignore +5 -1
  4. package/.prettierrc.js +2 -0
  5. package/.release-please-manifest.json +1 -1
  6. package/CHANGELOG.md +61 -0
  7. package/Dockerfile +8 -2
  8. package/README.md +1 -1
  9. package/bin/emailengine.js +444 -403
  10. package/copy-static-files.sh +39 -14
  11. package/data/google-crawlers.json +1 -1
  12. package/data/public_suffix_list.dat +16562 -0
  13. package/docker-compose.yml +1 -1
  14. package/eslint.config.js +81 -99
  15. package/lib/account/own-account-key.js +42 -0
  16. package/lib/account-assignment.js +1 -33
  17. package/lib/account.js +68 -24
  18. package/lib/add-trackers.js +11 -4
  19. package/lib/api-reference/format.js +4 -3
  20. package/lib/api-routes/account-routes.js +244 -26
  21. package/lib/api-routes/blocklist-routes.js +23 -2
  22. package/lib/api-routes/delivery-test-routes.js +26 -3
  23. package/lib/api-routes/export-routes.js +28 -2
  24. package/lib/api-routes/gateway-routes.js +37 -5
  25. package/lib/api-routes/mailbox-routes.js +41 -2
  26. package/lib/api-routes/message-routes.js +104 -4
  27. package/lib/api-routes/mint-bounds.js +11 -0
  28. package/lib/api-routes/oauth2-app-routes.js +48 -15
  29. package/lib/api-routes/outbox-routes.js +45 -11
  30. package/lib/api-routes/permission-map.js +12 -1
  31. package/lib/api-routes/route-helpers.js +125 -3
  32. package/lib/api-routes/settings-routes.js +23 -2
  33. package/lib/api-routes/submit-routes.js +338 -309
  34. package/lib/api-routes/template-routes.js +38 -2
  35. package/lib/api-routes/token-routes.js +142 -96
  36. package/lib/api-routes/webhook-route-routes.js +13 -2
  37. package/lib/auth-token.js +23 -10
  38. package/lib/bounce-detect.js +414 -210
  39. package/lib/consts.js +39 -4
  40. package/lib/create-imap-client.js +41 -2
  41. package/lib/email-client/base-client.js +30 -41
  42. package/lib/email-client/gmail-client.js +30 -18
  43. package/lib/email-client/imap/mailbox.js +13 -23
  44. package/lib/email-client/imap/response-metrics.js +75 -0
  45. package/lib/email-client/imap/subconnection.js +1 -1
  46. package/lib/email-client/imap-client.js +6 -3
  47. package/lib/email-client/message-builder.js +7 -2
  48. package/lib/email-client/notification-handler.js +1 -2
  49. package/lib/email-client/outlook/graph-api.js +17 -2
  50. package/lib/email-client/outlook-client.js +6 -3
  51. package/lib/email-client/smtp-pool-manager.js +6 -0
  52. package/lib/encrypt.js +9 -0
  53. package/lib/export.js +3 -1
  54. package/lib/gateway.js +2 -3
  55. package/lib/get-raw-email.js +4 -2
  56. package/lib/hapi-request-logger.js +107 -0
  57. package/lib/imap-proxy-auth.js +14 -1
  58. package/lib/imapproxy/imap-core/README.md +6 -5
  59. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +1 -0
  60. package/lib/imapproxy/imap-core/lib/commands/login.js +1 -0
  61. package/lib/imapproxy/imap-core/lib/imap-command.js +86 -43
  62. package/lib/imapproxy/imap-core/lib/imap-stream.js +58 -13
  63. package/lib/imapproxy/imap-core/lib/indexer/indexer.js +3 -1
  64. package/lib/mcp/listen.js +10 -1
  65. package/lib/mcp/tools.js +37 -8
  66. package/lib/notify-attachments.js +17 -0
  67. package/lib/oauth/external-account-config.js +3 -1
  68. package/lib/oauth/gmail.js +21 -48
  69. package/lib/oauth/mail-ru.js +5 -38
  70. package/lib/oauth/outlook-mailbox.js +35 -0
  71. package/lib/oauth/outlook.js +26 -44
  72. package/lib/oauth/state.js +24 -0
  73. package/lib/oauth2-apps.js +1 -1
  74. package/lib/pbkdf2-phc.js +19 -2
  75. package/lib/privileged-settings.js +6 -3
  76. package/lib/redis-scan-delete.js +15 -1
  77. package/lib/schemas.js +79 -33
  78. package/lib/settings.js +13 -1
  79. package/lib/smtp-auth.js +23 -0
  80. package/lib/sso.js +1 -1
  81. package/lib/swagger-options.js +1 -1
  82. package/lib/thread-diagnostics.js +46 -0
  83. package/lib/timezones.js +109 -0
  84. package/lib/token-permission-view.js +3 -3
  85. package/lib/tools.js +285 -66
  86. package/lib/totp.js +2 -5
  87. package/lib/translations.js +1 -2
  88. package/lib/ui-routes/account-routes.js +491 -491
  89. package/lib/ui-routes/account-setup.js +99 -0
  90. package/lib/ui-routes/admin-config-routes.js +98 -48
  91. package/lib/ui-routes/admin-entities-routes.js +113 -31
  92. package/lib/ui-routes/auth-routes.js +137 -62
  93. package/lib/ui-routes/connection-security-form.js +74 -0
  94. package/lib/ui-routes/form-lists.js +46 -0
  95. package/lib/ui-routes/internals-routes.js +5 -0
  96. package/lib/ui-routes/mcp-consent-routes.js +5 -1
  97. package/lib/ui-routes/oauth-config-routes.js +133 -100
  98. package/lib/ui-routes/route-helpers.js +19 -3
  99. package/lib/ui-routes/sign-in-helpers.js +59 -0
  100. package/lib/ui-routes/tls-config-routes.js +58 -15
  101. package/lib/ui-routes/unsubscribe-routes.js +6 -3
  102. package/lib/utils/back-off.js +82 -0
  103. package/lib/utils/map-concurrent.js +36 -0
  104. package/lib/utils/murmurhash3.js +66 -0
  105. package/lib/utils/network.js +28 -0
  106. package/lib/utils/provider-id.js +27 -0
  107. package/lib/utils/public-suffix.js +122 -0
  108. package/lib/utils/random-id.js +26 -0
  109. package/lib/utils/require-tls.js +33 -0
  110. package/lib/utils/version.js +74 -0
  111. package/lib/web-safe-html.js +5 -6
  112. package/lib/webhook-penalty.js +75 -0
  113. package/lib/webhook-routing.js +49 -2
  114. package/lib/webhooks.js +41 -6
  115. package/package.json +37 -39
  116. package/sbom.json +7980 -1
  117. package/server.js +659 -455
  118. package/static/js/ace/ace.js +1 -1
  119. package/static/js/ace/mode-handlebars.js +1 -1
  120. package/static/js/ace/mode-html.js +1 -1
  121. package/static/js/ace/mode-javascript.js +1 -1
  122. package/static/js/ace/mode-markdown.js +1 -1
  123. package/static/js/ace/worker-html.js +1 -1
  124. package/static/js/ace/worker-javascript.js +1 -1
  125. package/static/js/ace/worker-json.js +1 -1
  126. package/static/js/ee-client.js +5 -0
  127. package/static/licenses.html +191 -1016
  128. package/translations/messages.pot +70 -71
  129. package/views/account/security.hbs +10 -0
  130. package/views/accounts/account.hbs +11 -11
  131. package/views/accounts/edit.hbs +6 -2
  132. package/views/config/ai.hbs +1 -1
  133. package/views/config/security.hbs +2 -2
  134. package/views/config/service.hbs +3 -0
  135. package/views/internals/index.hbs +8 -0
  136. package/views/partials/gateway_form.hbs +3 -1
  137. package/views/partials/webhook_form.hbs +1 -1
  138. package/views/suppression-lists/index.hbs +1 -1
  139. package/workers/api.js +780 -585
  140. package/workers/export.js +1 -1
  141. package/workers/submit.js +1 -1
  142. package/workers/webhooks.js +54 -34
  143. package/config/test.toml +0 -46
  144. package/install.sh +0 -428
  145. package/setup-production.sh +0 -215
  146. package/systemd/emailengine.service +0 -97
  147. package/systemd/nginx-proxy.conf +0 -77
@@ -9,6 +9,7 @@ const { handleError, assertNoNetworkOverride } = require('./route-helpers');
9
9
  const BEHAVIOR = require('./behavior-notes');
10
10
  const { IMPACT } = require('./operation-impact');
11
11
  const { FIELD_USAGE } = require('../field-usage');
12
+ const { MAX_MAIL_MERGE_ENTRIES, MAX_DELIVERY_ATTEMPTS } = require('../consts');
12
13
  const {
13
14
  messageReferenceSchema,
14
15
  documentStoreSchema,
@@ -44,7 +45,7 @@ const sendAtSchema = Joi.date().iso().example('2021-07-08T07:06:34.336Z').descri
44
45
  const deliveryAttemptsSchema = Joi.number()
45
46
  .integer()
46
47
  .min(0)
47
- .max(100)
48
+ .max(MAX_DELIVERY_ATTEMPTS)
48
49
  .example(10)
49
50
  .description('How many delivery attempts to make until message is considered as failed');
50
51
 
@@ -94,8 +95,312 @@ const idempotencyResponseSchema = Joi.object({
94
95
  .description('Idempotency info, present when an Idempotency-Key header was used')
95
96
  .label('ResponseIdempotency');
96
97
 
97
- async function init(args) {
98
- 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;
99
404
 
100
405
  server.route({
101
406
  method: 'POST',
@@ -222,319 +527,19 @@ async function init(args) {
222
527
 
223
528
  headers: submitHeadersSchema,
224
529
 
225
- payload: Joi.object({
226
- reference: messageReferenceSchema,
227
-
228
- envelope: Joi.object({
229
- from: mailboxAddressSchema.allow('').example('sender@example.com'),
230
- to: Joi.array().items(mailboxAddressSchema.required().example('recipient@example.com')).single().label('SmtpEnvelopeTo')
231
- })
232
- .description('An optional object specifying the SMTP envelope used during email transmission')
233
- .meta({ usage: FIELD_USAGE.messageEnvelope })
234
- .label('SMTPEnvelope')
235
- .when('mailMerge', {
236
- is: Joi.exist().not(false, null),
237
- then: Joi.forbidden('y')
238
- }),
239
-
240
- raw: Joi.string()
241
- .base64()
242
- .max(MAX_ATTACHMENT_SIZE)
243
- .example('TUlNRS1WZXJzaW9uOiAxLjANClN1YmplY3Q6IGhlbGxvIHdvcmxkDQoNCkhlbGxvIQ0K')
244
- .description('A Base64-encoded email message in RFC 822 format')
245
- .meta({ usage: FIELD_USAGE.messageRaw })
246
- .label('RFC822Raw')
247
- .when('mailMerge', {
248
- is: Joi.exist().not(false, null),
249
- then: Joi.forbidden('y')
250
- }),
251
-
252
- from: fromAddressSchema,
253
-
254
- replyTo: Joi.array()
255
- .items(addressSchema.label('ReplyToAddress'))
256
- .single()
257
- .example([{ name: 'From Me', address: 'sender@example.com' }])
258
- .description('List of Reply-To addresses')
259
- .label('ReplyTo'),
260
-
261
- to: Joi.array()
262
- .items(addressSchema.label('ToAddress'))
263
- .single()
264
- .example([{ address: 'recipient@example.com' }])
265
- .description('List of recipient addresses')
266
- .label('ToAddressList')
267
- .when('mailMerge', {
268
- is: Joi.exist().not(false, null),
269
- then: Joi.forbidden('y')
270
- }),
271
-
272
- cc: Joi.array()
273
- .items(addressSchema.label('CcAddress'))
274
- .single()
275
- .description('List of CC addresses')
276
- .label('CcAddressList')
277
- .when('mailMerge', {
278
- is: Joi.exist().not(false, null),
279
- then: Joi.forbidden('y')
280
- }),
281
-
282
- bcc: Joi.array()
283
- .items(addressSchema.label('BccAddress'))
284
- .single()
285
- .description('List of BCC addresses')
286
- .label('BccAddressList')
287
- .when('mailMerge', {
288
- is: Joi.exist().not(false, null),
289
- then: Joi.forbidden('y')
290
- }),
291
-
292
- subject: templateSchemas.subject,
293
- text: templateSchemas.text,
294
- html: templateSchemas.html,
295
- previewText: templateSchemas.previewText,
296
-
297
- template: Joi.string().max(256).example('example').description('Stored template ID to load the email content from'),
298
-
299
- render: Joi.object({
300
- format: Joi.string()
301
- .valid('html', 'markdown')
302
- .default('html')
303
- .description('Markup language the template is written in')
304
- .meta({ enumDescriptions: ENUM_DESCRIPTIONS.renderFormat })
305
- .label('RenderFormat'),
306
- params: Joi.object()
307
- .label('RenderValues')
308
- .example({ firstName: 'Nyan', orderId: '4815' })
309
- .description('An object of variables for the template renderer')
310
- })
311
- .allow(false)
312
- .description('Template rendering options. Set to `false` to send the template as-is, without rendering it.')
313
- .when('mailMerge', {
314
- is: Joi.exist().not(false, null),
315
- then: Joi.forbidden('y')
316
- })
317
- .label('TemplateRender'),
318
-
319
- mailMerge: Joi.array()
320
- .items(
321
- Joi.object({
322
- to: addressSchema.label('ToAddress').required(),
323
- messageId: Joi.string().max(996).example('<test123@example.com>').description('Message ID'),
324
- params: Joi.object()
325
- .label('RenderValues')
326
- .example({ firstName: 'Nyan', orderId: '4815' })
327
- .description('An object of variables for the template renderer'),
328
- sendAt: Joi.date()
329
- .iso()
330
- .example('2021-07-08T07:06:34.336Z')
331
- .description('Send message at specified time. Overrides message level `sendAt` value.')
332
- }).label('MailMergeListEntry')
333
- )
334
- .min(1)
335
- .description('Mail merge options. A separate email is generated for each recipient')
336
- .meta({ usage: FIELD_USAGE.mailMerge })
337
- .label('MailMergeList'),
338
-
339
- attachments: Joi.array()
340
- .items(
341
- Joi.object({
342
- filename: Joi.string().max(256).example('transparent.gif'),
343
- content: Joi.string()
344
- .base64()
345
- .max(MAX_ATTACHMENT_SIZE)
346
- .required()
347
- .example('R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=')
348
- .description('Base64 formatted attachment file')
349
- .when('reference', {
350
- is: Joi.exist().not(false, null),
351
- then: Joi.forbidden(),
352
- otherwise: Joi.required()
353
- }),
354
-
355
- contentType: Joi.string().lowercase().max(256).example('image/gif'),
356
- contentDisposition: Joi.string().lowercase().valid('inline', 'attachment').label('AttachmentContentDisposition'),
357
- cid: Joi.string().max(256).example('unique-image-id@localhost').description('Content-ID value for embedded images'),
358
- encoding: Joi.string().valid('base64').default('base64').label('AttachmentEncoding'),
359
-
360
- reference: Joi.string()
361
- .base64({ paddingRequired: false, urlSafe: true })
362
- .max(256)
363
- .allow(false, null)
364
- .example('AAAAAQAACnAcde')
365
- .description('References an existing attachment by its ID instead of providing new attachment content')
366
- .meta({ usage: FIELD_USAGE.attachmentReference })
367
- .label('AttachmentReference')
368
- }).label('UploadAttachment')
369
- )
370
- .max(MAX_MESSAGE_ATTACHMENTS)
371
- .description('List of attachments')
372
- .label('UploadAttachmentList'),
373
-
374
- messageId: Joi.string().max(996).example('<test123@example.com>').description('Message ID'),
375
- headers: Joi.object().label('CustomHeaders').description('Custom Headers').unknown().example({
376
- 'X-My-Custom-Header': 'Custom header value'
377
- }),
378
-
379
- trackingEnabled: Joi.boolean()
380
- .example(false)
381
- .description('Should EmailEngine track clicks and opens for this message')
382
- .meta({ swaggerHidden: true }),
383
-
384
- trackOpens: Joi.boolean().example(false).description('Should EmailEngine track opens for this message'),
385
- trackClicks: Joi.boolean().example(false).description('Should EmailEngine track clicks for this message'),
386
-
387
- copy: Joi.boolean()
388
- .allow(null)
389
- .example(null)
390
- .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")
391
- .meta({ usage: FIELD_USAGE.messageCopy }),
392
-
393
- sentMailPath: Joi.string()
394
- .empty('')
395
- .max(1024)
396
- .example('Sent Mail')
397
- .description("Upload sent message to this folder. By default the account's Sent Mail folder is used."),
398
-
399
- locale: Joi.string().empty('').max(100).example('fr').description('Optional locale').label('MessageLocale'),
400
- tz: Joi.string().empty('').max(100).example('Europe/Tallinn').description('Optional timezone'),
401
-
402
- sendAt: sendAtSchema,
403
- deliveryAttempts: deliveryAttemptsSchema,
404
- gateway: gatewaySchema,
405
-
406
- listId: Joi.string()
407
- .hostname()
408
- .example('test-list')
409
- .description(
410
- 'List ID for Mail Merge. Must use a subdomain name format. Lists are registered ad-hoc, so a new identifier defines a new list.'
411
- )
412
- .label('ListID')
413
- .when('mailMerge', {
414
- is: Joi.exist().not(false, null),
415
- then: Joi.optional(),
416
- otherwise: Joi.forbidden()
417
- }),
418
-
419
- dsn: dsnSchema.label('DSN'),
420
-
421
- baseUrl: Joi.string()
422
- .trim()
423
- .empty('')
424
- .uri({
425
- scheme: ['http', 'https'],
426
- allowRelative: false
427
- })
428
- .example('https://customer123.myservice.com')
429
- .description('Optional base URL for trackers. This URL must point to your EmailEngine instance.'),
430
-
431
- proxy: proxySchema,
432
- localAddress: localAddressSchema,
433
-
434
- dryRun: apiBoolean()
435
- .default(false)
436
- .description(
437
- 'If true, then EmailEngine does not send the email and returns an RFC822 formatted email file. Tracking information is not added to the email.'
438
- )
439
- .label('Preview')
440
- })
441
- .oxor('raw', 'html')
442
- .oxor('raw', 'text')
443
- .oxor('raw', 'text')
444
- .oxor('raw', 'attachments')
445
- .label('SubmitMessage')
446
- .example({
447
- to: [
448
- {
449
- name: 'Nyan Cat',
450
- address: 'nyan.cat@example.com'
451
- }
452
- ],
453
- subject: 'What a wonderful message!',
454
- text: 'Hello from myself!',
455
- html: '<p>Hello from myself!</p>',
456
- attachments: [
457
- {
458
- filename: 'transparent.gif',
459
- content: 'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=',
460
- contentType: 'image/gif'
461
- }
462
- ]
463
- })
530
+ payload: buildSubmitMessagePayloadSchema(MAX_ATTACHMENT_SIZE)
464
531
  },
465
532
 
466
533
  response: {
467
- schema: Joi.object({
468
- response: Joi.string().example('Queued for delivery'),
469
- messageId: Joi.string()
470
- .example('<a2184d08-a470-fec6-a493-fa211a3756e9@example.com>')
471
- .description('Message-ID header value. Not present for bulk messages.'),
472
- queueId: Joi.string().example('d41f0423195f271f').description('Queue identifier for scheduled email. Not present for bulk messages.'),
473
- sendAt: Joi.date().example('2021-07-08T07:06:34.336Z').description('Scheduled send time'),
474
-
475
- reference: Joi.object({
476
- message: Joi.string()
477
- .base64({ paddingRequired: false, urlSafe: true })
478
- .max(256)
479
- .example('AAAAAQAACnA')
480
- .description('Referenced message ID. Not present when only a thread ID was referenced'),
481
- threadId: threadIdSchema.description('Referenced thread ID (Gmail API accounts only)').label('SubmitResponseReferenceThreadId'),
482
- success: Joi.boolean().example(true).description('Was the referenced message processed successfully').label('ResponseReferenceSuccess'),
483
- error: Joi.string().example('Referenced message was not found').description('An error message if referenced message processing failed')
484
- })
485
- .description('Reference info if referencing was requested')
486
- .label('ResponseReference'),
487
-
488
- preview: Joi.string()
489
- .base64()
490
- .example('Q29udGVudC1UeXBlOiBtdWx0aX...')
491
- .description('Base64 encoded RFC822 email if a preview was requested. Not returned for mail-merge submissions.')
492
- .label('ResponsePreview'),
493
-
494
- idempotency: idempotencyResponseSchema,
495
-
496
- mailMerge: Joi.array()
497
- .items(
498
- Joi.object({
499
- success: Joi.boolean().example(true).description('Was the message queued successfully').label('ResponseReferenceSuccess'),
500
- to: addressSchema.label('ToAddressSingle'),
501
- messageId: Joi.string().max(996).example('<test123@example.com>').description('Message ID'),
502
- queueId: Joi.string().example('d41f0423195f271f').description('Queue identifier for the scheduled email'),
503
- sendAt: Joi.date().iso().example('2021-07-08T07:06:34.336Z').description('Scheduled send time for this recipient'),
504
- error: Joi.string().example('Failed to queue message').description('Error message if queueing failed for this recipient'),
505
- code: Joi.string().example('EENVELOPE').description('Error code if queueing failed for this recipient'),
506
- statusCode: Joi.number()
507
- .integer()
508
- .allow(null)
509
- .example(500)
510
- .description('Error status code if queueing failed for this recipient'),
511
- skipped: Joi.object({
512
- reason: Joi.string().example('unsubscribe').description('Why this message was skipped'),
513
- listId: Joi.string().example('test-list')
514
- })
515
- .description('Info about skipped message. If this value is set, then the message was not sent')
516
- .label('SkippedMessageInfo')
517
- })
518
- .label('BulkResponseEntry')
519
- .example({
520
- success: true,
521
- to: {
522
- name: 'Andris 2',
523
- address: 'andris@ethereal.email'
524
- },
525
- messageId: '<19b9c433-d428-f6d8-1d00-d666ebcadfc4@ekiri.ee>',
526
- queueId: '1812477338914c8372a',
527
- sendAt: '2021-07-08T07:06:34.336Z'
528
- })
529
- .unknown()
530
- )
531
- .label('BulkResponseList')
532
- .description('Bulk message responses')
533
- }).label('SubmitMessageResponse'),
534
+ schema: buildSubmitMessageResponseSchema(),
534
535
  failAction: 'log'
535
536
  }
536
537
  }
537
538
  });
539
+ }
540
+
541
+ function registerSubmitDraft(server, args) {
542
+ const { call, CORS_CONFIG } = args;
538
543
 
539
544
  server.route({
540
545
  method: 'POST',
@@ -571,6 +576,23 @@ async function init(args) {
571
576
  tags: ['api', 'Submit'],
572
577
 
573
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
+ },
574
596
  openapi: {
575
597
  'x-ee-impact': IMPACT.SENDS,
576
598
  'x-ee-behavior': [BEHAVIOR.QUEUED_DELIVERY, BEHAVIOR.SENT_FOLDER_UPLOAD],
@@ -679,4 +701,11 @@ async function init(args) {
679
701
  });
680
702
  }
681
703
 
704
+ async function init(args) {
705
+ const { server } = args;
706
+
707
+ registerSubmitMessage(server, args);
708
+ registerSubmitDraft(server, args);
709
+ }
710
+
682
711
  module.exports = init;