You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add a webapi and webhooks for a simple http/json-based api
for applications to compose/send messages, receive delivery feedback, and
maintain suppression lists.
this is an alternative to applications using a library to compose messages,
submitting those messages using smtp, and monitoring a mailbox with imap for
DSNs, which can be processed into the equivalent of suppression lists. but you
need to know about all these standards/protocols and find libraries. by using
the webapi & webhooks, you just need a http & json library.
unfortunately, there is no standard for these kinds of api, so mox has made up
yet another one...
matching incoming DSNs about deliveries to original outgoing messages requires
keeping history of "retired" messages (delivered from the queue, either
successfully or failed). this can be enabled per account. history is also
useful for debugging deliveries. we now also keep history of each delivery
attempt, accessible while still in the queue, and kept when a message is
retired. the queue webadmin pages now also have pagination, to show potentially
large history.
a queue of webhook calls is now managed too. failures are retried similar to
message deliveries. webhooks can also be saved to the retired list after
completing. also configurable per account.
messages can be sent with a "unique smtp mail from" address. this can only be
used if the domain is configured with a localpart catchall separator such as
"+". when enabled, a queued message gets assigned a random "fromid", which is
added after the separator when sending. when DSNs are returned, they can be
related to previously sent messages based on this fromid. in the future, we can
implement matching on the "envid" used in the smtp dsn extension, or on the
"message-id" of the message. using a fromid can be triggered by authenticating
with a login email address that is configured as enabling fromid.
suppression lists are automatically managed per account. if a delivery attempt
results in certain smtp errors, the destination address is added to the
suppression list. future messages queued for that recipient will immediately
fail without a delivery attempt. suppression lists protect your mail server
reputation.
submitted messages can carry "extra" data through the queue and webhooks for
outgoing deliveries. through webapi as a json object, through smtp submission
as message headers of the form "x-mox-extra-<key>: value".
to make it easy to test webapi/webhooks locally, the "localserve" mode actually
puts messages in the queue. when it's time to deliver, it still won't do a full
delivery attempt, but just delivers to the sender account. unless the recipient
address has a special form, simulating a failure to deliver.
admins now have more control over the queue. "hold rules" can be added to mark
newly queued messages as "on hold", pausing delivery. rules can be about
certain sender or recipient domains/addresses, or apply to all messages pausing
the entire queue. also useful for (local) testing.
new config options have been introduced. they are editable through the admin
and/or account web interfaces.
the webapi http endpoints are enabled for newly generated configs with the
quickstart, and in localserve. existing configurations must explicitly enable
the webapi in mox.conf.
gopherwatch.org was created to dogfood this code. it initially used just the
compose/smtpclient/imapclient mox packages to send messages and process
delivery feedback. it will get a config option to use the mox webapi/webhooks
instead. the gopherwatch code to use webapi/webhook is smaller and simpler, and
developing that shaped development of the mox webapi/webhooks.
for issue #31 by cuu508
Copy file name to clipboardExpand all lines: config/config.go
+27-5Lines changed: 27 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -182,6 +182,8 @@ type Listener struct {
182
182
AdminHTTPSWebService`sconf:"optional" sconf-doc:"Admin web interface listener like AdminHTTP, but for HTTPS. Requires a TLS config."`
183
183
WebmailHTTPWebService`sconf:"optional" sconf-doc:"Webmail client, for reading email. Default path is /webmail/."`
184
184
WebmailHTTPSWebService`sconf:"optional" sconf-doc:"Webmail client, like WebmailHTTP, but for HTTPS. Requires a TLS config."`
185
+
WebAPIHTTPWebService`sconf:"optional" sconf-doc:"Like WebAPIHTTP, but with plain HTTP, without TLS."`
186
+
WebAPIHTTPSWebService`sconf:"optional" sconf-doc:"WebAPI, a simple HTTP/JSON-based API for email, with HTTPS (requires a TLS config). Default path is /webapi/."`
} `sconf:"optional" sconf-doc:"All configured WebHandlers will serve on an enabled listener. Either ACME must be configured, or for each WebHandler domain a TLS certificate must be configured."`
211
213
}
212
214
213
-
// WebService is an internal web interface: webmail, account, admin.
215
+
// WebService is an internal web interface: webmail, webaccount, webadmin, webapi.
214
216
typeWebServicestruct {
215
217
Enabledbool
216
218
Portint`sconf:"optional" sconf-doc:"Default 80 for HTTP and 443 for HTTPS."`
@@ -356,6 +358,19 @@ type Route struct {
356
358
357
359
// todo: move RejectsMailbox to store.Mailbox.SpecialUse, possibly with "X" prefix?
358
360
361
+
// note: outgoing hook events are in ../queue/hooks.go, ../mox-/config.go, ../queue.go and ../webapi/gendoc.sh. keep in sync.
362
+
363
+
typeOutgoingWebhookstruct {
364
+
URLstring`sconf-doc:"URL to POST webhooks."`
365
+
Authorizationstring`sconf:"optional" sconf-doc:"If not empty, value of Authorization header to add to HTTP requests."`
366
+
Events []string`sconf:"optional" sconf-doc:"Events to send outgoing delivery notifications for. If absent, all events are sent. Valid values: delivered, suppressed, delayed, failed, relayed, expanded, canceled, unrecognized."`
367
+
}
368
+
369
+
typeIncomingWebhookstruct {
370
+
URLstring`sconf-doc:"URL to POST webhooks to for incoming deliveries over SMTP."`
371
+
Authorizationstring`sconf:"optional" sconf-doc:"If not empty, value of Authorization header to add to HTTP requests."`
372
+
}
373
+
359
374
typeSubjectPassstruct {
360
375
Period time.Duration`sconf-doc:"How long unique values are accepted after generating, e.g. 12h."`// todo: have a reasonable default for this?
361
376
}
@@ -368,6 +383,12 @@ type AutomaticJunkFlags struct {
368
383
}
369
384
370
385
typeAccountstruct {
386
+
OutgoingWebhook*OutgoingWebhook`sconf:"optional" sconf-doc:"Webhooks for events about outgoing deliveries."`
387
+
IncomingWebhook*IncomingWebhook`sconf:"optional" sconf-doc:"Webhooks for events about incoming deliveries over SMTP."`
388
+
FromIDLoginAddresses []string`sconf:"optional" sconf-doc:"Login addresses that cause outgoing email to be sent with SMTP MAIL FROM addresses with a unique id after the localpart catchall separator (which must be enabled when addresses are specified here). Any delivery status notifications (DSN, e.g. for bounces), can be related to the original message and recipient with unique id's. You can login to an account with any valid email address, including variants with the localpart catchall separator. You can use this mechanism to both send outgoing messages both with and without unique fromid for a given address."`
389
+
KeepRetiredMessagePeriod time.Duration`sconf:"optional" sconf-doc:"Period to keep messages retired from the queue (delivered or failed) around. Keeping retired messages is useful for maintaining the suppression list for transactional email, for matching incoming DSNs to sent messages, and for debugging. The time at which to clean up (remove) is calculated at retire time. E.g. 168h (1 week)."`
390
+
KeepRetiredWebhookPeriod time.Duration`sconf:"optional" sconf-doc:"Period to keep webhooks retired from the queue (delivered or failed) around. Useful for debugging. The time at which to clean up (remove) is calculated at retire time. E.g. 168h (1 week)."`
391
+
371
392
Domainstring`sconf-doc:"Default domain for account. Deprecated behaviour: If a destination is not a full address but only a localpart, this domain is added to form a full address."`
372
393
Descriptionstring`sconf:"optional" sconf-doc:"Free form description, e.g. full name or alternative contact info."`
373
394
FullNamestring`sconf:"optional" sconf-doc:"Full name, to use in message From header when composing messages in webmail. Can be overridden per destination."`
@@ -383,10 +404,11 @@ type Account struct {
383
404
NoFirstTimeSenderDelaybool`sconf:"optional" sconf-doc:"Do not apply a delay to SMTP connections before accepting an incoming message from a first-time sender. Can be useful for accounts that sends automated responses and want instant replies."`
384
405
Routes []Route`sconf:"optional" sconf-doc:"Routes for delivering outgoing messages through the queue. Each delivery attempt evaluates these account routes, domain routes and finally global routes. The transport of the first matching route is used in the delivery attempt. If no routes match, which is the default with no configured routes, messages are delivered directly from the queue."`
385
406
386
-
DNSDomain dns.Domain`sconf:"-"`// Parsed form of Domain.
387
-
JunkMailbox*regexp.Regexp`sconf:"-" json:"-"`
388
-
NeutralMailbox*regexp.Regexp`sconf:"-" json:"-"`
389
-
NotJunkMailbox*regexp.Regexp`sconf:"-" json:"-"`
407
+
DNSDomain dns.Domain`sconf:"-"`// Parsed form of Domain.
0 commit comments