haerriz / module-smtprouting
Custom SMTP Routing module for Magento 2. Dynamically swaps SMTP credentials based on outgoing From address.
Package info
github.com/haerriz/module-smtprouting
Type:magento2-module
pkg:composer/haerriz/module-smtprouting
dev-main
2026-07-13 09:06 UTC
Requires
- php: ~7.4.0||~8.1.0||~8.2.0||~8.3.0
- magento/framework: *
- magento/module-email: *
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\Transportvia a lightweight Plugin. - Pulls credentials securely from Magento's
env.phpwithout 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
- 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' ],
- Configure your primary Magento SMTP fallback credentials in
Stores > Configuration > Advanced > System > SMTPas usual. If an email is sent that does not match a specific mapping inenv.php, it will fall back to the primary credentials.
License
MIT