Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Add Azure ACS bounce webhooks and settings support (#3001)

Oskari Kantoniemif4af26017ffc
diff --git a/cmd/bounce.go b/cmd/bounce.go
index 5235fa55..a407109f 100644
--- a/cmd/bounce.go
+++ b/cmd/bounce.go
@@ -182,6 +182,31 @@ func (a *App) BounceWebhook(c echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, a.i18n.T("globals.messages.invalidData"))
}
+ // Azure ACS through Event Grid.
+ case service == "azure" && a.bounce.Azure != nil:
+ switch c.Request().Header.Get("aeg-event-type") {
+ // Event Grid webhook registration validation.
+ case "SubscriptionValidation", "SubscriptionValidationEvent":
+ res, err := a.bounce.Azure.ProcessSubscription(rawReq)
+ if err != nil {
+ a.log.Printf("error processing Azure Event Grid subscription validation: %v", err)
+ return echo.NewHTTPError(http.StatusBadRequest, a.i18n.T("globals.messages.invalidData"))
+ }
+ return c.JSONBlob(http.StatusOK, res)
+
+ // Regular event delivery.
+ case "", "Notification":
+ bs, err := a.bounce.Azure.ProcessBounce(c.Request(), rawReq)
+ if err != nil {
+ a.log.Printf("error processing Azure Event Grid notification: %v", err)
+ return echo.NewHTTPError(http.StatusBadRequest, a.i18n.T("globals.messages.invalidData"))
+ }
+ bounces = append(bounces, bs...)
+
+ default:
+ return echo.NewHTTPError(http.StatusBadRequest, a.i18n.T("globals.messages.invalidData"))
+ }
+
// SendGrid.
case service == "sendgrid" && a.bounce.Sendgrid != nil:
var (
diff --git a/cmd/init.go b/cmd/init.go
index 84ffe172..00e6d67a 100644
--- a/cmd/init.go
+++ b/cmd/init.go
@@ -145,6 +145,7 @@ type Config struct {
BounceWebhooksEnabled bool
BounceSESEnabled bool
+ BounceAzureEnabled bool
BounceSendgridEnabled bool
BouncePostmarkEnabled bool
BounceForwardemailEnabled bool
@@ -511,6 +512,7 @@ func initConstConfig(ko *koanf.Koanf) *Config {
c.BounceWebhooksEnabled = ko.Bool("bounce.webhooks_enabled")
c.BounceSESEnabled = ko.Bool("bounce.ses_enabled")
+ c.BounceAzureEnabled = ko.Bool("bounce.azure.enabled")
c.BounceSendgridEnabled = ko.Bool("bounce.sendgrid_enabled")
c.BouncePostmarkEnabled = ko.Bool("bounce.postmark.enabled")
c.BounceForwardemailEnabled = ko.Bool("bounce.forwardemail.enabled")
@@ -819,10 +821,13 @@ func initNotifs(fs stuffbin.FileSystem, i *i18n.I18n, em *email.Emailer, u *UrlC
// for incoming bounce events.
func initBounceManager(cb func(models.Bounce) error, stmt *sqlx.Stmt, lo *log.Logger, ko *koanf.Koanf) *bounce.Manager {
opt := bounce.Opt{
- WebhooksEnabled: ko.Bool("bounce.webhooks_enabled"),
- SESEnabled: ko.Bool("bounce.ses_enabled"),
- SendgridEnabled: ko.Bool("bounce.sendgrid_enabled"),
- SendgridKey: ko.String("bounce.sendgrid_key"),
+ WebhooksEnabled: ko.Bool("bounce.webhooks_enabled"),
+ SESEnabled: ko.Bool("bounce.ses_enabled"),
+ AzureEnabled: ko.Bool("bounce.azure.enabled"),
+ AzureSharedSecret: ko.String("bounce.azure.shared_secret"),
+ AzureSharedSecretHeader: ko.String("bounce.azure.shared_secret_header"),
+ SendgridEnabled: ko.Bool("bounce.sendgrid_enabled"),
+ SendgridKey: ko.String("bounce.sendgrid_key"),
Postmark: struct {
Enabled bool
Username string
diff --git a/cmd/settings.go b/cmd/settings.go
index 5c1f5898..3482a14f 100644
--- a/cmd/settings.go
+++ b/cmd/settings.go
@@ -74,6 +74,7 @@ func (a *App) GetSettings(c echo.Context) error {
s.UploadS3AwsSecretAccessKey = strings.Repeat(pwdMask, utf8.RuneCountInString(s.UploadS3AwsSecretAccessKey))
s.SendgridKey = strings.Repeat(pwdMask, utf8.RuneCountInString(s.SendgridKey))
+ s.BounceAzure.SharedSecret = strings.Repeat(pwdMask, utf8.RuneCountInString(s.BounceAzure.SharedSecret))
s.BouncePostmark.Password = strings.Repeat(pwdMask, utf8.RuneCountInString(s.BouncePostmark.Password))
s.BounceForwardEmail.Key = strings.Repeat(pwdMask, utf8.RuneCountInString(s.BounceForwardEmail.Key))
s.BounceLettermint.Key = strings.Repeat(pwdMask, utf8.RuneCountInString(s.BounceLettermint.Key))
@@ -234,6 +235,9 @@ func (a *App) UpdateSettings(c echo.Context) error {
if set.SendgridKey == "" {
set.SendgridKey = cur.SendgridKey
}
+ if set.BounceAzure.SharedSecret == "" {
+ set.BounceAzure.SharedSecret = cur.BounceAzure.SharedSecret
+ }
if set.BouncePostmark.Password == "" {
set.BouncePostmark.Password = cur.BouncePostmark.Password
}
diff --git a/docs/docs/content/bounces.md b/docs/docs/content/bounces.md
index 99f02433..e41cabe7 100644
--- a/docs/docs/content/bounces.md
+++ b/docs/docs/content/bounces.md
@@ -48,6 +48,7 @@ listmonk supports receiving bounce webhook events from the following SMTP provid
| Endpoint | Description | More info |
|:--------------------------------------------------------------|:---------------------------------------|:----------------------------------------------------------------------------------------------------------------------|
| `https://listmonk.yoursite.com/webhooks/service/ses` | Amazon (AWS) SES | See below |
+| `https://listmonk.yoursite.com/webhooks/service/azure` | Azure Communication Services (ACS) | [More info](https://learn.microsoft.com/en-us/azure/event-grid/communication-services-email-events) |
| `https://listmonk.yoursite.com/webhooks/service/sendgrid` | Sendgrid / Twilio Signed event webhook | [More info](https://docs.sendgrid.com/for-developers/tracking-events/getting-started-event-webhook-security-features) |
| `https://listmonk.yoursite.com/webhooks/service/postmark` | Postmark webhook | [More info](https://postmarkapp.com/developer/webhooks/webhooks-overview) |
| `https://listmonk.yoursite.com/webhooks/service/forwardemail` | Forward Email webhook | [More info](https://forwardemail.net/en/faq#do-you-support-bounce-webhooks) |
@@ -91,6 +92,26 @@ If using SES as your SMTP provider, automatic bounce processing is the recommend
- Complaint: `[email protected]`
11. You can optionally [disable email feedback forwarding](https://docs.aws.amazon.com/ses/latest/dg/monitor-sending-activity-using-notifications-email.html#monitor-sending-activity-using-notifications-email-disabling).
+## Azure Communication Services (ACS)
+
+If you use Azure Communication Services Email, listmonk can receive delivery report events from Azure Event Grid and turn them into bounces.
+
+1. In listmonk settings, go to "Bounces" and configure:
+ - Enable bounce processing: `Enabled`
+ - Enable bounce webhooks: `Enabled`
+ - Enable Azure ACS: `Enabled`
+ - Optional: set `Azure Event Grid Shared Secret`.
+ - Optional: set `Azure Shared Secret Header Name` if you want listmonk to read the secret from a header (defaults to `X-Listmonk-Webhook-Secret`).
+2. In listmonk settings, go to "SMTP" and use the `Azure ACS` quick preset to fill SMTP defaults.
+3. In Azure, create an Event Grid subscription for your ACS Email events with:
+ - Endpoint type: `Web Hook`
+ - Endpoint URL: `https://listmonk.yoursite.com/webhooks/service/azure`
+ - If using query-param auth, append `?code=<your-shared-secret>`.
+ - If using header auth, configure Event Grid to include the same secret in the header name configured in listmonk.
+4. During subscription creation, Event Grid sends a subscription validation event. listmonk automatically returns `validationResponse` for this handshake.
+5. Subscribe to `Microsoft.Communication.EmailDeliveryReportReceived` events. listmonk maps relevant statuses to bounce records.
+6. Send test mail and verify bounces in listmonk.
+
## Exporting bounces
Bounces can be exported via the JSON API:
diff --git a/docs/docs/content/configuration.md b/docs/docs/content/configuration.md
index 38ec2fd2..d8f1f00f 100644
--- a/docs/docs/content/configuration.md
+++ b/docs/docs/content/configuration.md
@@ -45,7 +45,7 @@ When configuring auth proxies and web application firewalls, use this table.
| `GET, ` | `/link/*` | Tracked link redirection |
| `GET` | `/campaign/*` | Pixel tracking image |
| `GET` | `/public/*` | Static files for HTML subscription pages |
-| `POST` | `/webhooks/service/*` | Bounce webhook endpoints for AWS and Sendgrid |
+| `POST` | `/webhooks/service/*` | Bounce webhook endpoints for SES, Azure ACS, Sendgrid, and other supported providers |
| `GET` | `/uploads/*` | The file upload path configured in media settings |
diff --git a/docs/swagger/collections.yaml b/docs/swagger/collections.yaml
index 0394e19d..f12732ee 100644
--- a/docs/swagger/collections.yaml
+++ b/docs/swagger/collections.yaml
@@ -2844,6 +2844,8 @@ components:
type: string
settings.bounces.enableSES:
type: string
+ settings.bounces.enableAzure:
+ type: string
settings.bounces.enableSendgrid:
type: string
settings.bounces.enableForwardemail:
@@ -2860,6 +2862,14 @@ components:
type: string
settings.bounces.invalidScanInterval:
type: string
+ settings.bounces.azureSharedSecret:
+ type: string
+ settings.bounces.azureSharedSecretHelp:
+ type: string
+ settings.bounces.azureSharedSecretHeader:
+ type: string
+ settings.bounces.azureSharedSecretHeaderHelp:
+ type: string
settings.bounces.name:
type: string
settings.bounces.scanInterval:
@@ -3553,6 +3563,12 @@ components:
type: string
bounce.ses_enabled:
type: boolean
+ bounce.azure.enabled:
+ type: boolean
+ bounce.azure.shared_secret:
+ type: string
+ bounce.azure.shared_secret_header:
+ type: string
bounce.sendgrid_enabled:
type: boolean
bounce.sendgrid_key:
diff --git a/frontend/src/views/Settings.vue b/frontend/src/views/Settings.vue
index 60e98e02..34e19432 100644
--- a/frontend/src/views/Settings.vue
+++ b/frontend/src/views/Settings.vue
@@ -154,6 +154,12 @@ export default Vue.extend({
hasDummy = 'sendgrid';
}
+ if (this.isDummy(form['bounce.azure'].shared_secret)) {
+ form['bounce.azure'].shared_secret = '';
+ } else if (this.hasDummy(form['bounce.azure'].shared_secret)) {
+ hasDummy = 'azure shared secret';
+ }
+
if (this.isDummy(form['security.captcha'].hcaptcha.secret)) {
form['security.captcha'].hcaptcha.secret = '';
} else if (this.hasDummy(form['security.captcha'].hcaptcha.secret)) {
diff --git a/frontend/src/views/settings/bounces.vue b/frontend/src/views/settings/bounces.vue
index 2c8bedfe..a68d9061 100644
--- a/frontend/src/views/settings/bounces.vue
+++ b/frontend/src/views/settings/bounces.vue
@@ -65,6 +65,30 @@
</b-field>
</div>
</div>
+ <div class="columns">
+ <div class="column is-3">
+ <b-field>
+ <b-switch v-model="data['bounce.azure'].enabled" name="azure_enabled" :native-value="true"
+ data-cy="btn-enable-bounce-azure">
+ {{ $t('settings.bounces.enableAzure') }}
+ </b-switch>
+ </b-field>
+ </div>
+ <div class="column">
+ <b-field :label="$t('settings.bounces.azureSharedSecret')" :message="$t('settings.bounces.azureSharedSecretHelp')">
+ <b-input v-model="data['bounce.azure'].shared_secret" type="password"
+ :disabled="!data['bounce.azure'].enabled" name="azure_shared_secret"
+ data-cy="bounce-azure-shared-secret" />
+ </b-field>
+ </div>
+ <div class="column">
+ <b-field :label="$t('settings.bounces.azureSharedSecretHeader')" :message="$t('settings.bounces.azureSharedSecretHeaderHelp')">
+ <b-input v-model="data['bounce.azure'].shared_secret_header" type="text"
+ :disabled="!data['bounce.azure'].enabled" name="azure_shared_secret_header"
+ data-cy="bounce-azure-shared-secret-header" />
+ </b-field>
+ </div>
+ </div>
<div class="columns">
<div class="column is-3">
<b-field>
diff --git a/i18n/en.json b/i18n/en.json
index 5ec40f9d..3b1fc344 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -396,6 +396,7 @@
"settings.bounces.enableMailbox": "Enable bounce mailbox",
"settings.bounces.enablePostmark": "Enable Postmark",
"settings.bounces.enableSES": "Enable SES",
+ "settings.bounces.enableAzure": "Enable Azure ACS",
"settings.bounces.enableSendgrid": "Enable SendGrid",
"settings.bounces.enableWebhooks": "Enable bounce webhooks",
"settings.bounces.enabled": "Enabled",
@@ -413,6 +414,10 @@
"settings.bounces.scanInterval": "Scan interval",
"settings.bounces.scanIntervalHelp": "Interval at which the bounce mailbox should be scanned for bounces (s for second, m for minute).",
"settings.bounces.sendgridKey": "SendGrid Key",
+ "settings.bounces.azureSharedSecret": "Azure Event Grid Shared Secret",
+ "settings.bounces.azureSharedSecretHelp": "Provide the shared secret configured for your Azure Event Grid webhook endpoint.",
+ "settings.bounces.azureSharedSecretHeader": "Azure Shared Secret Header Name",
+ "settings.bounces.azureSharedSecretHeaderHelp": "Optional HTTP header name to read the Azure shared secret from. If empty, listmonk uses X-Listmonk-Webhook-Secret.",
"settings.bounces.type": "Type",
"settings.bounces.username": "Username",
"settings.confirmRestart": "Ensure running campaigns are paused. Restart?",
diff --git a/internal/bounce/bounce.go b/internal/bounce/bounce.go
index e8bcdcee..30b81f56 100644
--- a/internal/bounce/bounce.go
+++ b/internal/bounce/bounce.go
@@ -19,14 +19,17 @@ type Mailbox interface {
// Opt represents bounce processing options.
type Opt struct {
- MailboxEnabled bool `json:"mailbox_enabled"`
- MailboxType string `json:"mailbox_type"`
- Mailbox mailbox.Opt `json:"mailbox"`
- WebhooksEnabled bool `json:"webhooks_enabled"`
- SESEnabled bool `json:"ses_enabled"`
- SendgridEnabled bool `json:"sendgrid_enabled"`
- SendgridKey string `json:"sendgrid_key"`
- Postmark struct {
+ MailboxEnabled bool `json:"mailbox_enabled"`
+ MailboxType string `json:"mailbox_type"`
+ Mailbox mailbox.Opt `json:"mailbox"`
+ WebhooksEnabled bool `json:"webhooks_enabled"`
+ SESEnabled bool `json:"ses_enabled"`
+ AzureEnabled bool `json:"azure_enabled"`
+ AzureSharedSecret string `json:"azure_shared_secret"`
+ AzureSharedSecretHeader string `json:"azure_shared_secret_header"`
+ SendgridEnabled bool `json:"sendgrid_enabled"`
+ SendgridKey string `json:"sendgrid_key"`
+ Postmark struct {
Enabled bool
Username string
Password string
@@ -48,6 +51,7 @@ type Manager struct {
queue chan models.Bounce
mailbox Mailbox
SES *webhooks.SES
+ Azure *webhooks.Azure
Sendgrid *webhooks.Sendgrid
Postmark *webhooks.Postmark
Forwardemail *webhooks.Forwardemail
@@ -86,6 +90,9 @@ func New(opt Opt, q *Queries, lo *log.Logger) (*Manager, error) {
if opt.SESEnabled {
m.SES = webhooks.NewSES()
}
+ if opt.AzureEnabled {
+ m.Azure = webhooks.NewAzure(opt.AzureSharedSecret, opt.AzureSharedSecretHeader)
+ }
if opt.SendgridEnabled {
sg, err := webhooks.NewSendgrid(opt.SendgridKey)
diff --git a/internal/bounce/webhooks/azure.go b/internal/bounce/webhooks/azure.go
new file mode 100644
index 00000000..c6e024f0
--- /dev/null
+++ b/internal/bounce/webhooks/azure.go
@@ -0,0 +1,241 @@
+package webhooks
+
+import (
+ "crypto/subtle"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "net/http"
+ "regexp"
+ "strings"
+ "time"
+
+ "github.com/knadh/listmonk/models"
+)
+
+var reSMTPStatus = regexp.MustCompile(`\b([245]\.\d\.\d)\b`)
+
+type azureEvent struct {
+ EventType string `json:"eventType"`
+ Data azureEventData `json:"data"`
+ RawData json.RawMessage `json:"-"`
+}
+
+type azureEventData struct {
+ Recipient string `json:"recipient"`
+ MessageID string `json:"messageId"`
+ InternetMessageID string `json:"internetMessageId"`
+ Status string `json:"status"`
+ DeliveryStatusDetails azureDeliveryStatus `json:"deliveryStatusDetails"`
+ DeliveryAttemptTimestamp *time.Time `json:"deliveryAttemptTimestamp"`
+ DeliveryAttemptTimeStamp *time.Time `json:"deliveryAttemptTimeStamp"`
+ AdditionalData map[string]json.RawMessage `json:"-"`
+}
+
+type azureDeliveryStatus struct {
+ StatusMessage string `json:"statusMessage"`
+}
+
+// Azure handles webhook notifications from Azure Communication Services through Event Grid.
+type Azure struct {
+ sharedSecret string
+ sharedSecretHeader string
+}
+
+// NewAzure returns a new Azure webhook handler.
+func NewAzure(sharedSecret, sharedSecretHeader string) *Azure {
+ return &Azure{
+ sharedSecret: strings.TrimSpace(sharedSecret),
+ sharedSecretHeader: strings.TrimSpace(sharedSecretHeader),
+ }
+}
+
+// ProcessSubscription processes Event Grid subscription validation requests and
+// returns the response payload that should be written to HTTP response body.
+func (a *Azure) ProcessSubscription(b []byte) (json.RawMessage, error) {
+ events, err := parseAzureEvents(b)
+ if err != nil {
+ return nil, err
+ }
+ if len(events) == 0 {
+ return nil, errors.New("empty event payload")
+ }
+
+ // Validation code arrives in the first event for subscription validation flow.
+ var payload map[string]json.RawMessage
+ if err := json.Unmarshal(events[0].RawData, &payload); err != nil {
+ return nil, fmt.Errorf("error reading validation payload: %v", err)
+ }
+
+ rawData, ok := payload["data"]
+ if !ok {
+ return nil, errors.New("missing event data")
+ }
+
+ var data map[string]string
+ if err := json.Unmarshal(rawData, &data); err != nil {
+ return nil, fmt.Errorf("error reading validation data: %v", err)
+ }
+
+ code := strings.TrimSpace(data["validationCode"])
+ if code == "" {
+ return nil, errors.New("missing validationCode in subscription payload")
+ }
+
+ res, _ := json.Marshal(map[string]string{
+ "validationResponse": code,
+ })
+ return json.RawMessage(res), nil
+}
+
+// ProcessBounce parses Azure Event Grid email delivery events and returns bounce entries.
+func (a *Azure) ProcessBounce(req *http.Request, b []byte) ([]models.Bounce, error) {
+ if err := a.verifyAuth(req); err != nil {
+ return nil, err
+ }
+
+ events, err := parseAzureEvents(b)
+ if err != nil {
+ return nil, err
+ }
+
+ out := make([]models.Bounce, 0, len(events))
+ for _, ev := range events {
+ // Ignore non-delivery report events.
+ if ev.EventType != "Microsoft.Communication.EmailDeliveryReportReceived" {
+ continue
+ }
+
+ typ, ok := mapAzureStatus(ev.Data.Status, ev.Data.DeliveryStatusDetails.StatusMessage)
+ if !ok {
+ continue
+ }
+
+ email := strings.ToLower(strings.TrimSpace(ev.Data.Recipient))
+ if email == "" {
+ continue
+ }
+
+ tstamp := ev.Data.DeliveryAttemptTimestamp
+ if tstamp == nil {
+ tstamp = ev.Data.DeliveryAttemptTimeStamp
+ }
+
+ createdAt := time.Now()
+ if tstamp != nil && !tstamp.IsZero() {
+ createdAt = *tstamp
+ }
+
+ out = append(out, models.Bounce{
+ Email: email,
+ Type: typ,
+ Meta: json.RawMessage(ev.RawData),
+ Source: "azure",
+ CreatedAt: createdAt,
+ })
+ }
+
+ return out, nil
+}
+
+func (a *Azure) verifyAuth(req *http.Request) error {
+ const (
+ defaultSecretHeader = "X-Listmonk-Webhook-Secret"
+ querySecretParam = "code"
+ )
+
+ // If no local credential is configured, allow webhook payloads.
+ if a.sharedSecret == "" {
+ return nil
+ }
+
+ if req == nil {
+ return errors.New("missing azure event grid request context")
+ }
+
+ querySecret := strings.TrimSpace(req.URL.Query().Get(querySecretParam))
+ if secretsEqual(a.sharedSecret, querySecret) {
+ return nil
+ }
+
+ headerName := a.sharedSecretHeader
+ if headerName == "" {
+ headerName = defaultSecretHeader
+ }
+ headerSecret := strings.TrimSpace(req.Header.Get(headerName))
+ if secretsEqual(a.sharedSecret, headerSecret) {
+ return nil
+ }
+
+ return errors.New("invalid azure event grid shared secret")
+}
+
+func secretsEqual(expected, given string) bool {
+ if expected == "" || given == "" {
+ return false
+ }
+ return subtle.ConstantTimeCompare([]byte(expected), []byte(given)) == 1
+}
+
+func parseAzureEvents(b []byte) ([]azureEvent, error) {
+ var raws []json.RawMessage
+ if err := json.Unmarshal(b, &raws); err != nil {
+ return nil, fmt.Errorf("error unmarshalling azure notification array: %v", err)
+ }
+
+ events := make([]azureEvent, 0, len(raws))
+ for _, raw := range raws {
+ ev := azureEvent{RawData: raw}
+ if err := json.Unmarshal(raw, &ev); err != nil {
+ return nil, fmt.Errorf("error unmarshalling azure event: %v", err)
+ }
+ events = append(events, ev)
+ }
+
+ return events, nil
+}
+
+func mapAzureStatus(status, details string) (string, bool) {
+ s := strings.ToLower(strings.TrimSpace(status))
+ d := strings.ToLower(strings.TrimSpace(details))
+
+ switch s {
+ case "bounced", "suppressed":
+ return models.BounceTypeHard, true
+ case "failed":
+ // Infer severity from SMTP-enhanced status if available.
+ if m := reSMTPStatus.FindStringSubmatch(d); len(m) > 1 {
+ if strings.HasPrefix(m[1], "5.") {
+ return models.BounceTypeHard, true
+ }
+ if strings.HasPrefix(m[1], "4.") {
+ return models.BounceTypeSoft, true
+ }
+ }
+
+ if strings.Contains(d, "mailbox full") ||
+ strings.Contains(d, "temporar") ||
+ strings.Contains(d, "timeout") ||
+ strings.Contains(d, "rate limit") ||
+ strings.Contains(d, "throttle") {
+ return models.BounceTypeSoft, true
+ }
+ if strings.Contains(d, "invalid") ||
+ strings.Contains(d, "does not exist") ||
+ strings.Contains(d, "unknown user") ||
+ strings.Contains(d, "domain") {
+ return models.BounceTypeHard, true
+ }
+
+ return models.BounceTypeSoft, true
+ case "filteredspam", "quarantined":
+ if strings.Contains(d, "spam complaint") ||
+ strings.Contains(d, "complaint") ||
+ strings.Contains(d, "abuse") {
+ return models.BounceTypeComplaint, true
+ }
+ return models.BounceTypeSoft, true
+ default:
+ return "", false
+ }
+}
diff --git a/internal/migrations/v6.2.0.go b/internal/migrations/v6.2.0.go
index 941ebdae..7c07a399 100644
--- a/internal/migrations/v6.2.0.go
+++ b/internal/migrations/v6.2.0.go
@@ -40,6 +40,19 @@ func V6_2_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf, lo *log.Logger
return err
}
+ // Add `bounce.azure` for ACS/Event Grid bounce handling; upsert if the row already exists.
+ if _, err := db.Exec(`
+ INSERT INTO settings (key, value) VALUES('bounce.azure', '{"enabled": false, "shared_secret": "", "shared_secret_header": ""}')
+ ON CONFLICT (key) DO UPDATE
+ SET value = jsonb_build_object(
+ 'enabled', COALESCE((settings.value->>'enabled')::boolean, false),
+ 'shared_secret', COALESCE(settings.value->>'shared_secret', ''),
+ 'shared_secret_header', COALESCE(settings.value->>'shared_secret_header', '')
+ );
+ `); err != nil {
+ return err
+ }
+
if _, err := db.Exec(`INSERT INTO settings (key, value) VALUES ('app.show_optin_page', 'true') ON CONFLICT (key) DO NOTHING `); err != nil {
return err
}
diff --git a/models/settings.go b/models/settings.go
index f4c2c278..33a27327 100644
--- a/models/settings.go
+++ b/models/settings.go
@@ -123,7 +123,12 @@ type Settings struct {
SESEnabled bool `json:"bounce.ses_enabled"`
SendgridEnabled bool `json:"bounce.sendgrid_enabled"`
SendgridKey string `json:"bounce.sendgrid_key"`
- BouncePostmark struct {
+ BounceAzure struct {
+ Enabled bool `json:"enabled"`
+ SharedSecret string `json:"shared_secret"`
+ SharedSecretHeader string `json:"shared_secret_header"`
+ } `json:"bounce.azure"`
+ BouncePostmark struct {
Enabled bool `json:"enabled"`
Username string `json:"username"`
Password string `json:"password"`
diff --git a/schema.sql b/schema.sql
index edf8299e..5b3c08d6 100644
--- a/schema.sql
+++ b/schema.sql
@@ -286,6 +286,7 @@ INSERT INTO settings (key, value) VALUES
('bounce.webhooks_enabled', 'false'),
('bounce.actions', '{"soft": {"count": 2, "action": "none"}, "hard": {"count": 1, "action": "blocklist"}, "complaint" : {"count": 1, "action": "blocklist"}}'),
('bounce.ses_enabled', 'false'),
+ ('bounce.azure', '{"enabled": false, "shared_secret": "", "shared_secret_header": ""}'),
('bounce.sendgrid_enabled', 'false'),
('bounce.sendgrid_key', '""'),
('bounce.postmark', '{"enabled": false, "username": "", "password": ""}'),