haerriz/module-smtprouting

Custom SMTP Routing module for Magento 2. Dynamically swaps SMTP credentials based on outgoing From address.

Maintainers

Package info

github.com/haerriz/module-smtprouting

Type:magento2-module

pkg:composer/haerriz/module-smtprouting

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-07-13 09:06 UTC

This package is auto-updated.

Last update: 2026-08-16 07:16:23 UTC


README

A lightweight Magento 2 module that dynamically intercepts outgoing emails and swaps the SMTP authentication credentials based on the From email address.

This is extremely useful for shared hosting environments (like Hostinger) that enforce strict anti-spoofing policies (e.g., 553 Sender address rejected: not owned by user), requiring the SMTP login to match the exact outgoing email address.

Features

  • Bypasses strict anti-spoofing policies on shared hosting.
  • Natively intercepts Magento's core Magento\Email\Model\Transport via a lightweight Plugin.
  • Pulls credentials securely from Magento's env.php without hardcoding passwords in the database.
  • Completely eliminates the need for bulky, paid SMTP extensions.

Installation via Composer

composer require haerriz/module-smtprouting
bin/magento module:enable Haerriz_SmtpRouting
bin/magento setup:upgrade
bin/magento setup:di:compile

Configuration

  1. In your server's app/etc/env.php, add an array mapping your sender emails to their SMTP passwords:
'smtp_mapping' => [
    'orders@yourstore.com' => 'orders_password',
    'newsletter@yourstore.com' => 'newsletter_password',
    'support@yourstore.com' => 'support_password'
],
  1. Configure your primary Magento SMTP fallback credentials in Stores > Configuration > Advanced > System > SMTP as usual. If an email is sent that does not match a specific mapping in env.php, it will fall back to the primary credentials.

License

MIT