Best way to implement backup SMTP connection

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
cjr
Posts: 14
Joined: 08 Jul 2020, 16:58

Best way to implement backup SMTP connection

Post by cjr » 16 Feb 2021, 19:08

We have had issues with our SMPT provider failing and want to establish a backup account to send emails when needed.

What would be the best way to implement it?
I'm looking in to extending the SwiftMailer classes, but have run in to issues with passing the message in.

Argument 1 passed to Swift_Transport_AbstractSmtpTransport::send() must be an in stance of Swift_Mime_SimpleMessage, instance of Aimeos\MW\Mail\Message\Swift given.


Bottom line is we want to be able to just use different SMPT credentials should the main ones fail.

User avatar
aimeos
Administrator
Posts: 7873
Joined: 01 Jan 1970, 00:00

Re: Best way to implement backup SMTP connection

Post by aimeos » 18 Feb 2021, 07:37

You can implement a decorator (a wrapper class with the same interface, like an onion) that calls the underlying ai-swiftmailer class and if it throws an exception, send the e-mail to an alternative provider. Additonally, you have to extend the Aimeos context object and add your decorator instead of the Laravel Swiftmailer object here:
https://github.com/aimeos/aimeos-larave ... #L180-L185
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

cjr
Posts: 14
Joined: 08 Jul 2020, 16:58

Re: Best way to implement backup SMTP connection

Post by cjr » 18 Feb 2021, 14:26

Thank you,

So far I extended:
vendor\aimeos\aimeos-laravel\src\Aimeos\Shop\Base\Context.php
vendor\aimeos\aimeos-core\lib\mshoplib\src\MShop\Context\Item\Iface.php
vendor\aimeos\aimeos-core\lib\mshoplib\src\MShop\Context\Item\Standard.php

to have a getMailBackup() and SetMailBackup(). The entire site is getting a 500 in the browser without any logs in the storage/logs or madmin_log table.

I'm not sure which files I missed to add the extension.

User avatar
aimeos
Administrator
Posts: 7873
Joined: 01 Jan 1970, 00:00

Re: Best way to implement backup SMTP connection

Post by aimeos » 20 Feb 2021, 08:56

Wrong way. You should:
- Extend the swiftmailer class and overwrite the send() method to resend the e-mail with an alternative SMTP configuration in case of an error
- Use that class in a Laravel ServiceProvider to create the "mailer" object

Thus, you don't need to change anything in Aimeos but only create a Laravel ServiceProvider and your own Swiftmailer class.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply