Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
## [Unreleased]

### Added

* **SendGrid EU regional subusers.** A SendGrid account now has a region: **Global** (default, `api.sendgrid.com`) or **EU** (`api.eu.sendgrid.com`). If your SendGrid key belongs to an EU regional subuser, open the account, choose region **EU** and save. Existing accounts keep the global host; nothing changes for them. An unknown region is rejected when the account is saved.
* **Mailgun sends carry Magic Mail metadata.** Each Mailgun mail gets the variables `magicmail_email_type`, `magicmail_priority` and `magicmail_id` (the email log id) and one tag with the email type (`transactional`, `marketing` or `notification`), so you can filter Mailgun's logs and webhooks by type. SendGrid mails carry `magicmail_id` as a custom argument. Mailgun shows variables to recipients in the `X-Mailgun-Variables` header; they contain no personal data.

### Fixed

* **Duplicate recipients no longer make SendGrid reject the whole email.** SendGrid refuses a mail when an address appears twice in to, cc or bcc. Magic Mail now sends every address once (the first occurrence wins, compared without case) and drops a cc or bcc list that only repeated other addresses. Other providers are unchanged (Mailgun ignores duplicates itself).
* **SendGrid keeps recipient names.** `Ada Lovelace <ada@example.com>` arrives as "Ada Lovelace" instead of the bare address.
* **The SendGrid connection test names a missing Mail Send permission.** SendGrid answers a key without the Mail Send permission with the same 401 as a wrong key, so the test used to say "SendGrid rejected the API key". After a 401 or 403 the test now makes one read-only call (`GET /v3/scopes`): a valid key without Mail Send gets its own hint (`SENDGRID_MISSING_MAIL_SEND`), a wrong key keeps the old one. Nothing from SendGrid's answer is shown.
* **Oversized emails are rejected before upload with a clear message.** SendGrid accepts less than 30 MB and Mailgun 25 MB per message. Magic Mail now checks the size before calling the provider and answers with a validation error (`MAGIC_MAIL_MESSAGE_TOO_LARGE`) instead of uploading the whole mail and getting a vague rejection. All attachments of one email together may be at most 40 MB raw with every provider (each file stays limited to 25 MB). A provider's own "too large" answer (HTTP 413) gets the same code.
* **Magic Mail turns off Mailgun's and SendGrid's own open/click tracking when it tracks itself, so links are no longer wrapped twice** and opens are not counted twice. Only the part Magic Mail really applied is switched off; when Magic Mail does not track (tracking off, no public URL), the provider's tracking settings apply as before.
* **Clear error when headers are too large for Mailgun.** Mailgun allows 16 KB for all headers and options of one message. A Mailgun message above that is now refused before sending with `MAGIC_MAIL_MESSAGE_TOO_LARGE` instead of a bare Mailgun 400. Custom headers are still sent exactly as before; nothing is dropped or shortened.
* **SendGrid's reserved headers are filtered.** A caller header `X-SG-ID` or `X-SG-EID` used to make SendGrid reject the mail; Magic Mail now drops them like its own reserved headers.
* **Clearer provider failures.** Failed SendGrid and Mailgun calls now carry the provider and, for SendGrid, the names of the rejected fields (for example `personalizations.0.cc`), never the provider's message text (it can contain addresses). The error message stays `SendGrid API request failed: <status>`. The server log names the region. When SendGrid answers 429 with a reset time, a queued retry waits at least until then.

### Verification

* SendGrid: every change above was tested live against the real SendGrid API in sandbox mode on 2026-11-18 (sending, account check, webhooks). The EU host could not be tested live (no EU subuser).
* Mailgun: the changes are verified against Mailgun's official OpenAPI specification and with tests, but not yet against the live Mailgun API. Please report anything unexpected.

### Migration

* If you use a SendGrid EU regional subuser, set that account's region to **EU**.
* If you listen to SendGrid or Mailgun webhooks yourself, you will see the new `magicmail_*` custom arguments / variables and the Mailgun tag.

## [4.6.3](https://github.com/Schero94/Magic-Mail/compare/v4.6.2...v4.6.3) (2026-11-18)


Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ MagicMail sends email only. It is MIT licensed, with no license key, tiers or us

## What's new

- **SendGrid EU regional subusers:** choose region **EU** in the account to send through `api.eu.sendgrid.com` ([setup](https://github.com/Schero94/Magic-Mail/blob/main/docs/sending.md#sendgrid)).
- **Fewer provider rejections:** duplicate recipients, SendGrid-reserved headers and oversized messages are handled before the request, with a clear error instead of a bare HTTP status.
- **No double tracking:** when MagicMail tracks opens and clicks, SendGrid and Mailgun tracking is switched off for that mail, so links are wrapped once.
- **Mailgun metadata:** email type and priority as variables plus a tag, so Mailgun logs and webhooks can be filtered.
- **Mailgun domains are checked when you save the account.** A pasted `https://` or trailing slash is removed for you; a value that is not a domain name is flagged right in the form instead of failing later when mail is sent.
- **Failed account tests say what to fix:** wrong API key, missing Mail Send permission, unverified sender, wrong Mailgun region, or a sandbox recipient that is not authorized yet.
- **Clearer key setup:** the wizard recommends keys that can only send mail (SendGrid Custom Access with Mail Send, Mailgun Domain Sending Key).
Expand Down Expand Up @@ -252,6 +256,8 @@ npm run verify
npm run verify:runtime
```

`npm run test:live` runs the opt-in suite against the real SendGrid and Mailgun APIs (SendGrid sandbox mode and Mailgun test mode, nothing is delivered; Mailgun bills test-mode messages). It reads `~/.config/magic-mail-live/.env` with `SENDGRID_API_KEY`, `SENDGRID_FROM`, `MAILGUN_API_KEY`, `MAILGUN_DOMAIN`, `MAILGUN_REGION`, `LIVE_TEST_RECIPIENT` and optionally `SENDGRID_REGION`, `SENDGRID_EU_API_KEY`, `SENDGRID_EU_FROM`, `MAILGUN_FROM`, `MAILGUN_EU_DOMAIN`, `MAILGUN_EU_API_KEY`; without the file every live test is skipped. Never commit that file.

`npm run test:admin` renders every admin entry point (the five sections of the MagicMail page with their dialogs, the template editor, the Plugin Settings page) inside `React.StrictMode` with the providers of the Strapi admin, in jsdom with a fake network. It fails on a mutation sent twice, a read repeated without aborting the first one, an interval, listener, connection or observer left after unmount, and any console error or warning. A separate CI job runs the same tests against React 19 for information only: the plugin's peer range is React 18, like the Strapi 5 admin.

`npm run test:multi-instance` runs the multi-process suite (set `MAGIC_MAIL_TEST_PG_URL` for PostgreSQL). `npm run watch` (or `npm run watch:link` with yalc) rebuilds the admin and the server bundle on change. CI runs the same checks on Node 22 and 24 for every pull request and every push to `main`. Use [Conventional Commits](https://www.conventionalcommits.org/) (`fix:`, `feat:`, `docs:`); releases are cut from `main` by semantic-release.
Expand Down
27 changes: 27 additions & 0 deletions admin/src/components/AccountWizard/CredentialsStep.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,33 @@ export const CredentialsStep = ({
<MailgunDomainField form={form} onChange={onChange} isEditMode={isEditMode} />
)}

{provider === 'sendgrid' && (
<FullWidthField>
<Field.Root
hint={t(
'accountModal.sendgrid.regionHint',
'Use EU only for an EU regional subuser. EU accounts are called through api.eu.sendgrid.com, all others through api.sendgrid.com.'
)}
required
name="sendgridRegion"
>
<Field.Label>{t('accountModal.sendgrid.region', 'SendGrid region')}</Field.Label>
<SingleSelect
value={form.sendgridRegion}
onChange={(value) => onChange('sendgridRegion', value)}
>
<SingleSelectOption value="us">
{t('accountModal.sendgrid.regionGlobal', 'Global (api.sendgrid.com)')}
</SingleSelectOption>
<SingleSelectOption value="eu">
{t('accountModal.sendgrid.regionEu', 'EU (api.eu.sendgrid.com)')}
</SingleSelectOption>
</SingleSelect>
<Field.Hint />
</Field.Root>
</FullWidthField>
)}

{provider === 'mailgun' && (
<FullWidthField>
<Field.Root
Expand Down
5 changes: 5 additions & 0 deletions admin/src/components/AccountWizard/wizardState.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const createEmptyForm = () => ({
apiKey: '',
mailgunDomain: '',
mailgunRegion: 'us',
sendgridRegion: 'us',
webhookPublicKey: '',
webhookSigningKey: '',
microsoftTenantId: '',
Expand Down Expand Up @@ -143,6 +144,8 @@ export const accountToForm = (account = {}) => {
mailgunDomain: stringOr(config.domain),
// Accounts saved before regions existed use the US endpoint.
mailgunRegion: config.region === 'eu' ? 'eu' : 'us',
// SendGrid EU regional subusers use api.eu.sendgrid.com.
sendgridRegion: config.region === 'eu' ? 'eu' : 'us',
// Optional bounce/complaint webhook secrets (SendGrid key is public).
webhookPublicKey: stringOr(config.webhookPublicKey),
webhookSigningKey: stringOr(config.webhookSigningKey),
Expand Down Expand Up @@ -345,6 +348,8 @@ export const buildConfig = (provider, form) => {
case 'sendgrid':
return {
apiKey: form.apiKey.trim(),
// "us" = api.sendgrid.com (global), "eu" = api.eu.sendgrid.com.
region: form.sendgridRegion === 'eu' ? 'eu' : 'us',
webhookPublicKey: (form.webhookPublicKey || '').trim(),
};
case 'mailgun':
Expand Down
7 changes: 6 additions & 1 deletion admin/src/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"accounts.test.hint.mailgunUnauthorized": "Mailgun hat den API-Schlüssel abgelehnt. Prüfen Sie den Schlüssel und die Region: Eine in der EU-Region angelegte Domain benötigt die EU-Region.",
"accounts.test.hint.rateLimited": "Der Anbieter begrenzt die Anfragen. Warten Sie einen Moment und versuchen Sie es erneut.",
"accounts.test.hint.sendgridForbidden": "SendGrid hat die Anfrage verweigert. Prüfen Sie, ob der API-Schlüssel die Berechtigung Mail Send hat und die Absenderadresse eine verifizierte Sender Identity ist.",
"accounts.test.hint.sendgridMissingMailSend": "Der SendGrid-API-Schlüssel ist gültig, hat aber nicht die Berechtigung Mail Send. Geben Sie dem Schlüssel Zugriff auf Mail Send oder erstellen Sie einen Schlüssel mit dieser Berechtigung.",
"accounts.test.hint.sendgridPayloadTooLarge": "SendGrid hat die Nachricht als zu groß abgelehnt. Verkleinern Sie Inhalt und Anhänge.",
"accounts.test.hint.sendgridUnauthorized": "SendGrid hat den API-Schlüssel abgelehnt. Prüfen Sie, ob der Schlüssel vollständig kopiert und nicht gelöscht wurde.",
"accounts.test.mode": "Testmodus",
Expand Down Expand Up @@ -924,5 +925,9 @@
"suppressions.empty.description": "Empfänger erscheinen hier nach einem dauerhaften Bounce.",
"suppressions.pagination": "Seiten der Sperrliste",
"suppressions.confirm.title": "Aus der Sperrliste entfernen?",
"suppressions.confirm.body": "E-Mails an {address} werden wieder versendet. Nur entfernen, wenn die Adresse korrigiert wurde."
"suppressions.confirm.body": "E-Mails an {address} werden wieder versendet. Nur entfernen, wenn die Adresse korrigiert wurde.",
"accountModal.sendgrid.regionHint": "Wählen Sie EU nur für einen regionalen EU-Subuser. EU-Konten werden über api.eu.sendgrid.com aufgerufen, alle anderen über api.sendgrid.com.",
"accountModal.sendgrid.region": "SendGrid-Region",
"accountModal.sendgrid.regionGlobal": "Global (api.sendgrid.com)",
"accountModal.sendgrid.regionEu": "EU (api.eu.sendgrid.com)"
}
7 changes: 6 additions & 1 deletion admin/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"accounts.test.hint.mailgunUnauthorized": "Mailgun rejected the API key. Check the key and the region: a domain created in the EU region needs the EU region.",
"accounts.test.hint.rateLimited": "The provider is rate limiting requests. Wait a moment and try again.",
"accounts.test.hint.sendgridForbidden": "SendGrid refused the request. Check that the API key has the Mail Send permission and that the From address is a verified Sender Identity.",
"accounts.test.hint.sendgridMissingMailSend": "The SendGrid API key is valid but does not have the Mail Send permission. Give the key Mail Send access or create a key that has it.",
"accounts.test.hint.sendgridPayloadTooLarge": "SendGrid rejected the message as too large. Reduce the size of the content and attachments.",
"accounts.test.hint.sendgridUnauthorized": "SendGrid rejected the API key. Check that the key was copied completely and has not been deleted.",
"accounts.test.mode": "Test mode",
Expand Down Expand Up @@ -924,5 +925,9 @@
"suppressions.empty.description": "Recipients appear here after a permanent bounce.",
"suppressions.pagination": "Suppression list pages",
"suppressions.confirm.title": "Remove from the suppression list?",
"suppressions.confirm.body": "Emails to {address} are sent again. Only do this when the address was fixed."
"suppressions.confirm.body": "Emails to {address} are sent again. Only do this when the address was fixed.",
"accountModal.sendgrid.regionHint": "Use EU only for an EU regional subuser. EU accounts are called through api.eu.sendgrid.com, all others through api.sendgrid.com.",
"accountModal.sendgrid.region": "SendGrid region",
"accountModal.sendgrid.regionGlobal": "Global (api.sendgrid.com)",
"accountModal.sendgrid.regionEu": "EU (api.eu.sendgrid.com)"
}
7 changes: 6 additions & 1 deletion admin/src/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"accounts.test.hint.mailgunUnauthorized": "Mailgun ha rechazado la clave de API. Compruebe la clave y la región: un dominio creado en la región UE necesita la región UE.",
"accounts.test.hint.rateLimited": "El proveedor está limitando las solicitudes. Espere un momento y vuelva a intentarlo.",
"accounts.test.hint.sendgridForbidden": "SendGrid ha rechazado la solicitud. Compruebe que la clave de API tenga el permiso Mail Send y que la dirección del remitente sea una Sender Identity verificada.",
"accounts.test.hint.sendgridMissingMailSend": "La clave de API de SendGrid es válida, pero no tiene el permiso Mail Send. Dé a la clave acceso a Mail Send o cree una clave que lo tenga.",
"accounts.test.hint.sendgridPayloadTooLarge": "SendGrid ha rechazado el mensaje por ser demasiado grande. Reduzca el tamaño del contenido y de los adjuntos.",
"accounts.test.hint.sendgridUnauthorized": "SendGrid ha rechazado la clave de API. Compruebe que la clave se haya copiado completa y que no se haya eliminado.",
"accounts.test.mode": "Modo de prueba",
Expand Down Expand Up @@ -924,5 +925,9 @@
"suppressions.empty.description": "Los destinatarios aparecen aquí tras un rebote permanente.",
"suppressions.pagination": "Páginas de la lista de bloqueo",
"suppressions.confirm.title": "¿Quitar de la lista de bloqueo?",
"suppressions.confirm.body": "Los correos a {address} se volverán a enviar. Hazlo solo si la dirección se ha corregido."
"suppressions.confirm.body": "Los correos a {address} se volverán a enviar. Hazlo solo si la dirección se ha corregido.",
"accountModal.sendgrid.regionHint": "Elija EU solo para un subusuario regional de la EU. Las cuentas de la EU se llaman a través de api.eu.sendgrid.com; todas las demás, a través de api.sendgrid.com.",
"accountModal.sendgrid.region": "Región de SendGrid",
"accountModal.sendgrid.regionGlobal": "Global (api.sendgrid.com)",
"accountModal.sendgrid.regionEu": "EU (api.eu.sendgrid.com)"
}
7 changes: 6 additions & 1 deletion admin/src/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"accounts.test.hint.mailgunUnauthorized": "Mailgun a refusé la clé API. Vérifiez la clé et la région : un domaine créé dans la région UE nécessite la région UE.",
"accounts.test.hint.rateLimited": "Le fournisseur limite les requêtes. Patientez un instant, puis réessayez.",
"accounts.test.hint.sendgridForbidden": "SendGrid a refusé la requête. Vérifiez que la clé API dispose de l’autorisation Mail Send et que l’adresse d’expéditeur est une Sender Identity vérifiée.",
"accounts.test.hint.sendgridMissingMailSend": "La clé API SendGrid est valide mais ne dispose pas de l’autorisation Mail Send. Accordez l’accès Mail Send à la clé ou créez une clé qui en dispose.",
"accounts.test.hint.sendgridPayloadTooLarge": "SendGrid a refusé le message, car il est trop volumineux. Réduisez la taille du contenu et des pièces jointes.",
"accounts.test.hint.sendgridUnauthorized": "SendGrid a refusé la clé API. Vérifiez que la clé a été copiée entièrement et n’a pas été supprimée.",
"accounts.test.mode": "Mode de test",
Expand Down Expand Up @@ -924,5 +925,9 @@
"suppressions.empty.description": "Les destinataires apparaissent ici après un rebond permanent.",
"suppressions.pagination": "Pages de la liste de blocage",
"suppressions.confirm.title": "Retirer de la liste de blocage ?",
"suppressions.confirm.body": "Les e-mails vers {address} seront de nouveau envoyés. À faire uniquement si l'adresse a été corrigée."
"suppressions.confirm.body": "Les e-mails vers {address} seront de nouveau envoyés. À faire uniquement si l'adresse a été corrigée.",
"accountModal.sendgrid.regionHint": "Choisissez EU uniquement pour un sous-utilisateur régional EU. Les comptes EU sont appelés via api.eu.sendgrid.com, tous les autres via api.sendgrid.com.",
"accountModal.sendgrid.region": "Région SendGrid",
"accountModal.sendgrid.regionGlobal": "Mondiale (api.sendgrid.com)",
"accountModal.sendgrid.regionEu": "EU (api.eu.sendgrid.com)"
}
7 changes: 6 additions & 1 deletion admin/src/translations/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
"accounts.test.hint.mailgunUnauthorized": "O Mailgun recusou a chave de API. Verifique a chave e a região: um domínio criado na região UE precisa da região UE.",
"accounts.test.hint.rateLimited": "O provedor está limitando as solicitações. Aguarde um momento e tente novamente.",
"accounts.test.hint.sendgridForbidden": "O SendGrid recusou a solicitação. Verifique se a chave de API tem a permissão Mail Send e se o endereço do remetente é uma Sender Identity verificada.",
"accounts.test.hint.sendgridMissingMailSend": "A chave de API do SendGrid é válida, mas não tem a permissão Mail Send. Dê à chave acesso ao Mail Send ou crie uma chave que tenha essa permissão.",
"accounts.test.hint.sendgridPayloadTooLarge": "O SendGrid recusou a mensagem por ser grande demais. Reduza o tamanho do conteúdo e dos anexos.",
"accounts.test.hint.sendgridUnauthorized": "O SendGrid recusou a chave de API. Verifique se a chave foi copiada por completo e não foi excluída.",
"accounts.test.mode": "Modo de teste",
Expand Down Expand Up @@ -924,5 +925,9 @@
"suppressions.empty.description": "Os destinatários aparecem aqui após uma devolução permanente.",
"suppressions.pagination": "Páginas da lista de bloqueio",
"suppressions.confirm.title": "Remover da lista de bloqueio?",
"suppressions.confirm.body": "Os e-mails para {address} voltam a ser enviados. Faça-o apenas se o endereço foi corrigido."
"suppressions.confirm.body": "Os e-mails para {address} voltam a ser enviados. Faça-o apenas se o endereço foi corrigido.",
"accountModal.sendgrid.regionHint": "Escolha EU apenas para um subusuário regional da EU. As contas da EU são chamadas por meio de api.eu.sendgrid.com; todas as outras, por meio de api.sendgrid.com.",
"accountModal.sendgrid.region": "Região do SendGrid",
"accountModal.sendgrid.regionGlobal": "Global (api.sendgrid.com)",
"accountModal.sendgrid.regionEu": "EU (api.eu.sendgrid.com)"
}
Loading
Loading