Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email is no longer dispatched via Mandrill #37

Closed
Silarn opened this issue May 25, 2017 · 14 comments
Closed

Email is no longer dispatched via Mandrill #37

Silarn opened this issue May 25, 2017 · 14 comments
Assignees
Milestone

Comments

@Silarn
Copy link
Contributor

Silarn commented May 25, 2017

The fix for #30 actually broke Mandrill email. It does allow the system to bypass it when it isn't enabled, but it effectively prevents sending email through Mandrill.

I'll see about creating an official PR tomorrow, but in order to fix this locally I had to create a new plugin and disable the Transport plugin:

    <type name="Magento\Framework\Mail\TransportInterfaceFactory">
        <plugin name="fixMandrillTransport" type="Namespace\Module\Plugin\Mail\TransportInterfaceFactory"/>
    </type>
    <type name="Magento\Framework\Mail\Transport">
        <plugin name="mandrill-send-message" disabled="true" />
    </type>

and create the new class like so

<?php
namespace Namespace\Module\Plugin\Mail;

class TransportInterfaceFactory
{
    /**
     * Mandrill Transport Factory
     *
     * @var \Ebizmarts\Mandrill\Model\TransportFactory
     */
    protected $mandrillTransportFactory;

    /**
     * Mandrill Helper class
     *
     * @var \Ebizmarts\Mandrill\Helper\Data
     */
    protected $mandrillHelper;

    /**
     * TransportBuilder constructor.
     * @param \Ebizmarts\Mandrill\Helper\Data $mandrillHelper
     * @param \Ebizmarts\Mandrill\Model\TransportFactory $mandrillTransportFactory
     */
    public function __construct(
        \Ebizmarts\Mandrill\Helper\Data $mandrillHelper,
        \Ebizmarts\Mandrill\Model\TransportFactory $mandrillTransportFactory
    ) {
        $this->mandrillHelper = $mandrillHelper;
        $this->mandrillTransportFactory = $mandrillTransportFactory;
    }

    /**
     * Replace mail transport with Mandrill if needed
     *
     * @param \Magento\Framework\Mail\TransportInterfaceFactory $subject
     * @param \Closure $proceed
     * @param array $data
     *
     * @return \Magento\Framework\Mail\TransportInterface
     */
    public function aroundCreate(
        \Magento\Framework\Mail\TransportInterfaceFactory $subject,
        \Closure $proceed,
        array $data = []
    ) {
        if ($this->isMandrillEnabled() === false) {
            /** @var \Magento\Framework\Mail\TransportInterface $transport */
            $transport = $proceed($data);
            return $transport;
        } else {
            return $this->mandrillTransportFactory->create($data);
        }
    }

    /**
     * Get status of Mandrill
     *
     * @return bool
     */
    private function isMandrillEnabled()
    {
        return $this->mandrillHelper->isMandrillEnabled();
    }
}
@centerax centerax self-assigned this May 25, 2017
@Silarn Silarn changed the title Email is no longer dispatch via Mandrill Email is no longer dispatched via Mandrill May 26, 2017
@centerax
Copy link
Member

Im not seeing such error. Tested again on the latest release and emails are sent out. Maybe its something else on your setup, another extension or something.

@Silarn
Copy link
Contributor Author

Silarn commented May 31, 2017

We don't have any other extensions hooking into the mail system. It makes perfect sense to me. The current version instantiates the mandrill transport model but never passes the message data from the transport builder to the instantiated model. It then 'sends' the mail with no message being set.

Instead, you hook into transport factory 'create' method which sets that data and switcheroo the model being created (passing in the message data from the plugged-in function). You pretty much have to do it this way because the transport builder doesn't have publicly accessible data, only setters. When it creates the transport model, it passes the message data to the factory.

If it makes any difference, we're running Magento 2.1.6.

@centerax
Copy link
Member

can you post here some logs from your Mandrill API logs to see the message without content?

@lgrassini
Copy link

lgrassini commented Jul 19, 2017

Same here, Mails not being sent at all (not even the Test Email)...
The only API calls showing in the log are the /users/info.json.

I'm getting the following error: "No body specified".
Magento 2.1.6.

@centerax

@lgrassini
Copy link

@Silarn Can you please elaborate how do you fixed this? I'm having exactly the same problem you reported. Thanks you!

@Silarn
Copy link
Contributor Author

Silarn commented Jul 21, 2017

@centerax The message is never sent because there is no message data in the Transport model. There's no log to show you. I'll try to detail my fix in a second post.

@Silarn
Copy link
Contributor Author

Silarn commented Jul 21, 2017

In my earlier post I opted to use a new module with a plugin as a fix rather than changing the module code.

The first portion was the contents of the Namespace_NewModule <module_dir>/etc/di.xml file.

The second portion is a file you need to create under <module_dir>/Plugin/Mail/TransportInterfaceFactory.php`.

In addition, you need a basic /etc/module.xml file, composer.json file, and registration.php file.

Here is a basic tutorial.

@centerax
Copy link
Member

@Silarn if the body is empty that should not prevent the message from being sent, you can send an empty email. But if you say there is no log on Mandill, thats ok.

@Silarn
Copy link
Contributor Author

Silarn commented Jul 21, 2017

It's not the mail body. It's all of the message data. There is no data in the transport model so nothing is sent.

@centerax
Copy link
Member

I was not able to replicate this case. Testing on 2.1.7 at the moment without success to have an empty object

@lgrassini
Copy link

Thank you @Silarn !
I was able to get my emails dispatched by applying @Silarn fix.
@centerax Please consider reviewing the implementation of the fix #30 is definitely breaking the magento2-mandrill extension.

@Silarn
Copy link
Contributor Author

Silarn commented Jul 22, 2017

@lgrassini I've recently created a PR containing this change which they've merged into their development branch. You can give that a try instead of relying on this secondary module method.

@lgrassini
Copy link

Thanks @Silarn ... So far it is working with your fix. I will wait until they merge your PR into the stable branch.

@centerax
Copy link
Member

guys: we will release a new version with this included tomorrow.

@centerax centerax mentioned this issue Jul 24, 2017
@centerax centerax modified the milestone: 3.0.12 Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants