SparkPost Mail Transport for XF 2.3

SparkPost Mail Transport for XF 2.3 5.1.0

No permission to download
Thanks to @Sim for this wonderful add-on!

Using SparkPost EU with this add-on​

If your SparkPost account is in the EU region, you'll see this when testing the add-on out of the box:

Code:
GuzzleHttp\Exception\ClientException:
POST https://api.sparkpost.com/api/v1/transmissions/ -> 401 Unauthorized
{"errors":[{"message":"Unauthorized."}]}

Why it happens​

EU and US are separate SparkPost environments. EU API keys only work with api.eu.sparkpost.com, not api.sparkpost.com.

Below are the steps to make the add-on work with SparkPost EU (currently at: https://app.eu.sparkpost.com/).
I'm sure there are better ways, but LLM's got me lazy.

Quick self-check if needed: which region does your key work in?​

Run these in terminal (safe "sandbox" send - no real mail goes out):

Bash:
# US host
curl -sS -X POST https://api.sparkpost.com/api/v1/transmissions \
  -H "Authorization: YOUR_EU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"options":{"sandbox":true},"content":{"from":"postmaster@yourdomain.tld","subject":"XF test","text":"hi"},"recipients":[{"address":"test@example.com"}]}'

# EU host
curl -sS -X POST https://api.eu.sparkpost.com/api/v1/transmissions \
  -H "Authorization: YOUR_EU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"options":{"sandbox":true},"content":{"from":"postmaster@yourdomain.tld","subject":"XF test","text":"hi"},"recipients":[{"address":"test@example.com"}]}'

If US = 401 and EU = 200, your key is EU (expected). Proceed to the next step

---

Point the add-on at the EU API host​


The add-on's Symfony Mailer transport builds the host from a region parameter.
Current builds don't pass it, so it defaults to US. 2 tiny patches you can use (pick one):

Option A. - Pass the region when constructing the transport (better)​

Edit:
src/addons/Hampel/SparkPostMail/SubContainer/SparkPost.php

Change:
PHP:
return new SparkPostApiTransport($apikey, $client);

to:
PHP:
return new SparkPostApiTransport($apikey, $client, null, null, 'eu');
// or, to hardcode the host explicitly:
// return new SparkPostApiTransport($apikey, $client, null, null, null, 'api.eu.sparkpost.com');

Option B - Hardcode the EU URL at the call site (sledgehammer)​

Edit:
src/addons/Hampel/SparkPostMail/vendor/hampel/symfonymailer-sparkpost/src/Transport/SparkPostApiTransport.php

Find this line in doSendApi():
PHP:
\sprintf('https://%s/api/v1/transmissions/', $this->host)
Replace with:
PHP:
'https://api.eu.sparkpost.com/api/v1/transmissions/'

After editing, in case of opcode or some other cache, you might need to restart PHP (php-fpm / LiteSpeed / Apache / Nginx whateva') so the cache picks up the changes.

Then re-run ACP → Tools → Test SparkPost.

If the first line now shows:
Code:
POST https://api.eu.sparkpost.com/api/v1/transmissions/
you're on the right host..
 
There is a problem with Painbaker's Moderator Tools add-on. When it sends notification emails, it does not check whether the target user still exists. If the user has been deleted, null is passed to your add-on, which then throws an exception.

I'm not sure where this should be fixed. It could be argued that the add-on sending the email should verify that all required data exists before attempting to send it. On the other hand, the mail add-on could also handle this case gracefully. Perhaps both add-ons should validate their input.

I have already informed Painbaker.
https://xenforo.com/community/threads/xb-moderator-tools-paid.185317/page-2#post-1789549
 
Sim updated SparkPost Mail Transport for XF 2.3 with a new update entry:

v4.0.1

4.0.1 (2026-09-03)​


  • bugfix: message event processing failed when the Monolog addon was not installed
  • bugfix: SparkPost error details render correctly again on the outbound email test page - the
    message, description and error code fields were empty and the code shown was the HTTP status
    rather than SparkPost's own
  • remove a template modification which no longer matched any XenForo 2.3 template
  • align the bundled Symfony packages with the...

Read the rest of this update entry...
 
Note - if you are running php 8.3 or higher, you might want to wait for the upcoming v5.0.0 release of this addon, which includes a complete rebuild of the entire sparkpost transport path, but is not compatible with earlier versions of php. You are welcome to install addon v4.x now and then upgrade to v5.x later - both versions will work on php 8.3

If you run php 8.1 or 8.2 (and XenForo 2.3), then v4.x of this addon is for you - I've been running v4.0.0 in production for a year now - I just never got around to publishing it.
 
Sim updated SparkPost Mail Transport for XF 2.3 with a new update entry:

v5.1.0 - major rewrite

Addon now uses the well-tested hampel/sparkpost and hampel/sparkpost-transport packages for sending and communicating with SparkPost.

5.1.0 (2026-10-14)​

  • new: sparkpost:config reports what this forum is set up to do and where each value came
    from - the selected transport, whether an API key is set and which host it points at, test mode,
    click and open tracking, the message event page size and the fetch...

Read the rest of this update entry...
 
Back
Top Bottom