jdavidbakr / mail-tracker

Package for Laravel to inject tracking code into outgoing emails.
MIT License
577 stars 129 forks source link

Unavailable with Laravel Octane? #149

Closed maher1337 closed 1 year ago

maher1337 commented 3 years ago

The package seems not be working with octane currently, correct me if I'm wrong thank you!

jdavidbakr commented 3 years ago

I've never used Octane but I don't know why it wouldn't work. I am running all of my stuff in Docker containers and this package works without any issues. What are your symptoms?

maher1337 commented 3 years ago

When I'm running using artisan serve, the sent_emails table gets populated and everything is in place. however with Octane it does not insert any email log and I can not seem to the trace the error because there is none that's thrown.

jdavidbakr commented 3 years ago

Interesting. Do you know if Octane does anything to override the swift mailer? Again, I really don't know what Octane might be doing but if it's not working then either the swift mailer is getting loaded later in the Octane environment or somehow the MailTrackerServiceProvider is not getting called.

maher1337 commented 3 years ago

I think the reason behind this is if you look at the register() function in class MailTrackerServiceProvider I think the package has to be registred for it to run on Octane.

maher1337 commented 3 years ago

https://laravel.com/docs/8.x/octane#dependency-injection-and-octane

maher1337 commented 3 years ago

I'm not 100% sure of how the package is built I need more time to analyze the code. However if I push the email to a rabbitMQ queue and the worker handles the email it works perfectly fine as supposed to.

fibis commented 3 years ago

I think that this is an issue with the amazon sdk. We use mailcoach for newsletters, and here are also problems with octane and the tracking of SNS webhooks.

jdavidbakr commented 2 years ago

I am not sure what needs to be changed to make this work in Octane. If the mailer is getting rebooted every time but the service provider is not, then it may be something you need to add to your application to hook in the swift mailer plugin freshly one every request that you need to send mail to. Unless you all have an idea or pull request that resolves this, I'm going to close this issue.

gabrielpeixoto commented 1 year ago

I had a problem with the code called by vendor/aws/aws-php-sns-message-validator/src/Message.php in the line that tries to get file_get_contents('php://input'), because in Octane it doesn't It worked.

A suggestion to resolve the issue would be to modify vendor/jdavidbakr/mail-tracker/src/SNSController.php by modifying the $message = SNSMessage::fromRawPostData(); part to:

// get body from request
$body = $request->getContent();

// Make sure the SNS-provided header exists.
if (!isset($_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE'])) {
     throw new \RuntimeException('SNS message type header not provided.');
}

$message = SNSMessage::fromJsonString($body);
jdavidbakr commented 1 year ago

That does look more Laravel-correct. Feel free to submit a PR.