magento-2-smtp icon indicating copy to clipboard operation
magento-2-smtp copied to clipboard

Multiple stores with different SMTP options fail when `Asynchronous sending` is enabled

Open lphilippo opened this issue 3 years ago • 3 comments

Preconditions (*)

  1. Magento 2.4.2
  2. Turn on Asynchronous sending

Steps to reproduce (*)

  1. Configure different SMTP options for different stores
  2. Schedule a single email for two different stores.

Expected result (*)

  1. Two emails being sent when the cron runs, each with their own SMTP options.

Actual result (*)

  1. Both emails are being sent with the SMTP options of the first email.

Additional information

When during a single cron run, multiple emails are processed from different stores (with different SMTP options), the SMTP options are not being adjusted on the second or next message.

In Mageplaza\Smtp\Mail\Rse\Mail::getTransport($storeId) the $this->_transport is not being reinstantiated, when it's called with another store-ID than as used for the existing value. The store ID is only being used during actual initialisation, as only happens during the first request.

If we adjust the code to force $this->_transport to be reinstantiated every time it's called (better compare or cache it), the expected behaviour is achieved, as both emails are processed with their correct SMTP settings.

lphilippo avatar Aug 25 '21 20:08 lphilippo

Hi,

This is my first time having this problem so I don't know how to reproduce the problem yet. Can you please provide me with a screen shot that reproduces the issue in detail so I can check it out? Thank you!

HuyPhuc98 avatar Aug 29 '21 14:08 HuyPhuc98

Hello @HuyPhuc98

Screenshots will probably not be very helpful here. I've created a PR containing our local fix, which should explain the issue much quicker, I think:

https://github.com/mageplaza/magento-2-smtp/pull/332

We simply saw that wrong SMTP settings were applied to emails, when we had a lot of confirmation emails (of different shops). This had the undesired effect that although the emails were being delivered, the wrong SMTP server was exposed in some emails. If you would like more specific information, please let me know.

lphilippo avatar Aug 30 '21 09:08 lphilippo

Thank you very much for your feedback. We will check your fix.

HuyPhuc98 avatar Sep 13 '21 11:09 HuyPhuc98