# Mautic Integration w/ Sendgrid API

**URL:** <https://forum.mautic.org/t/mautic-integration-w-sendgrid-api/38177>\
**Category:** Product Support\
**Created:** [May 1, 2026, 11:14pm UTC](https://forum.mautic.org/t/mautic-integration-w-sendgrid-api/38177 "2026-05-01T23:14:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![royalty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/royalty/32/15028_2.png) [@royalty](https://forum.mautic.org/u/royalty)\
**Post date:** [May 1, 2026, 11:14pm UTC](https://forum.mautic.org/t/mautic-integration-w-sendgrid-api/38177/1 "2026-05-01T23:14:48Z")

</div>

**Your software**  
My Mautic version is: 7.0.1  
My PHP version is: 8.2.30  
My Database type and version is: MySQL 8.4.9  
I installed Mautic via: Zip

**Your problem**  
My problem is:

Mautic returns a 401 “authorization grant is invalid” error on every email send attempt, even though the SendGrid API key is valid and works correctly when tested directly against SendGrid’s API.

**Environment:**

- LiteSpeed web server via cPanel shared/VPS hosting
- symfony/sendgrid-mailer (v7.4.0) installed via composer
- DSN configured in config/local.php as:  
‘mailer\_dsn’ =\> ‘sendgrid+api://apikey:SG.xxx@default’
- Domain authentication completed in SendGrid (DKIM/SPF/CNAMEs verified)
- Single sender [hello@royaltymarketing.com](mailto:hello@royaltymarketing.com) verified
- Outbound HTTPS to [api.sendgrid.com](http://api.sendgrid.com) works (curl test below confirms)

**Verification that the API key is valid:**

- Running curl from the Mautic server:  
curl -H “Authorization: Bearer $KEY” [https://api.sendgrid.com/v3/scopes](https://api.sendgrid.com/v3/scopes)  
Returns HTTP 200 with full scopes list including “mail.send”
- Sending mail directly via curl to SendGrid’s /v3/mail/send endpoint with the same key successfully delivers to the inbox

**Verification that DSN is correctly configured:**

- grep mailer\_dsn config/local.php shows the clean DSN, no whitespace or hidden characters
- hexdump confirms the DSN is byte-perfect (length 99 = 22-char prefix + 69-char key + 8-char suffix)
- Bug in app/bundles/ConfigBundle/Form/DataTransformer/DsnTransformer.php (PASSWORD\_MASK = ‘🔒’) was previously corrupting the saved DSN with %F0%9F%94%92 prefix when saving via Configuration UI — avoiding that UI now and only editing local.php directly

**These errors are showing in the log:**

[2026-05-01T22:14:37+00:00] app.ERROR: [MAIL ERROR] Unable to send an email: The provided authorization grant is invalid, expired, or revoked(code 401). {“hostname”:“[host.royaltymarketing.com](http://host.royaltymarketing.com)”,“pid”:3866527}

This identical error appears on every send attempt regardless of which API key is in use (key has been rotated 4+ times, each tested working via curl before being installed).

**Steps I have tried to fix the problem:**

1. Verified API key works via curl from the Mautic server — HTTP 200 to /v3/scopes, successful test send via /v3/mail/send
2. Confirmed config/local.php has clean ‘mailer\_dsn’ =\> ‘sendgrid+api://apikey:KEY@default’ (no lock-icon corruption)
3. Tried using .env.local with MAUTIC\_MAILER\_DSN env var (Symfony 500-errored when present, removed)
4. rm -rf var/cache/prod && php bin/console cache:warmup --env=prod --no-debug
5. rm -rf var/tmp/twig
6. Force-restarted LiteSpeed workers via touch tmp/restart.txt
7. opcache\_reset() via web request to confirm SAPI=litespeed picked up new code
8. Verified php bin/console debug:dotenv shows MAUTIC\_MAILER\_DSN correctly loaded (when .env.local was present)
9. Verified php bin/console debug:container --parameter=mautic.mailer\_dsn shows %env(nullable:resolve:MAUTIC\_MAILER\_DSN)% (resolves at runtime)
10. Verified DSN reaches LiteSpeed worker via \_\_check.php — $\_ENV[‘MAUTIC\_MAILER\_DSN’] is correct length (99) with no lock emoji
11. Confirmed the symfony/sendgrid-mailer bridge package is installed (without it, the error message is different — “the bridge is not installed”)
12. Tried SMTP via [smtp.sendgrid.net:587](http://smtp.sendgrid.net:587) — outbound port 587 is blocked by host firewall (Connection refused)

**What I’d expect:**  
Mautic should send the request to SendGrid’s API using my configured key.

**What’s happening:**  
Mautic sends the request and SendGrid responds with 401, suggesting Mautic is sending the wrong/empty/garbled key — but I cannot find where the wrong value is coming from.

Has anyone seen this combination of “valid API key + correctly configured DSN + still gets 401” on Mautic 7 with LiteSpeed?

---

<div class="post-metadata">

**Author:** ![alexzlobin](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexzlobin/32/13606_2.png) [@alexzlobin](https://forum.mautic.org/u/alexzlobin)\
**Post date:** [May 4, 2026, 6:53pm UTC](https://forum.mautic.org/t/mautic-integration-w-sendgrid-api/38177/2 "2026-05-04T18:53:22Z")

</div>

Hi

must be

```
    'mailer_dsn' => 'sendgrid+api://SGxxxxxxxxxxx@default',

```

Also if you want SNS you can use plugins for bounce
