Closed IonutOjicaDE closed 11 months ago
@IonutOjicaDE I ran into a similar problem.
I therefore forked the repo and made changes. In today's mass mailing to approx. 900 contacts, the bounces and complaints were processed perfectly and stored in Mautic.
Take a look https://github.com/Pacerino/MauticPostalServerBundle
@Pacerino Thank you ! Very much ! I have 2 points:
Your code:
/**
* Handle bounces & complaints from Postal.
*/
public function processCallbackRequest(Request $request)
{
$postData = json_decode($request->getContent(), true);
$event = $postData['event'];
$payload = $postData['payload'];
$message = isset($payload['original_message']) ? $payload['original_message'] : $payload['message'];
$email = $message['to'];
if ('MessageDeliveryFailed' == $event) {
$this->transportCallback->addFailureByAddress($email, $this->translator->trans('mautic.email.bounce.reason.other'));
} elseif ('MessageBounced' == $event) {
$this->transportCallback->addFailureByAddress($email, $this->translator->trans('mautic.email.bounce.reason.hard_bounce'));
}
}
Changed to:
/**
* Handle bounces & complaints from Postal.
From: https://github.com/Pacerino/MauticPostalServerBundle
as an example for transportCallback->addFailureByAddress see: https://forum.mautic.org/t/webhook-postmark-support-management-of-bounces-spam-and-unsubscription/25799/2?u=ionutojicade
*/
public function processCallbackRequest(Request $request): void
{
$postData = json_decode($request->getContent(), true);
$event = $postData['event'];
$payload = $postData['payload'];
$message = isset($payload['original_message']) ? $payload['original_message'] : $payload['message'];
$email = $message['to'];
if ('MessageDeliveryFailed' == $event || 'MessageBounced' == $event) {
$output = ('MessageDeliveryFailed' == $event)
? $this->translator->trans('mautic.email.bounce.reason.other')
: $this->translator->trans('mautic.email.bounce.reason.hard_bounce');
$output .= ": " . $payload['output'] . "[Postal: " . $payload['details'] . "]";
//error_log("output: " . $output . "\n", 3, "/var/www/html/m/var/logs/postal.log");
$this->transportCallback->addFailureByAddress($email, $output, DoNotContact::BOUNCED);
}
}
We should implement some sort of authentication, otherwise anyone can send Mautic this type of webhook. I found an example that works with the current version of Postal, but I do not know how to implement it in Mautic:
@IonutOjicaDE Thank you for your contribution!
I've implemented the Webhhok signature checker. Could you try it? My understanding is that you need to add the public key under the Config.php https://github.com/Pacerino/MauticPostalServerBundle/blob/master/Config/config.php#L45
/opt/postal/config
openssl rsa -in signing.key -pubout
BEGIN PUBLIC KEY
and END PUBLIC KEY
into the above configExample:
'parameters' => [
'mailer_postal_webhook_signing_key' => 'MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgF4w4tegq4rIWjPddTTaOCG6SMQx1MXbD4s5Wxx1x+Ao761eqeCGinmxy0wIGMMux21EGkr9IkMeU2dtCopMPFuMsb8hTZs7DhbfQ7BPttp7CxrzDhgEEVJOMrTl9KbDWYvSUozPHOLASLQwlJXuLrYj3leDNL2nui4J8x+mFzAgMBAAE=',
],
I haven't tested it yet. I've ran into other problems the last few days and had to disable the postal server unil i've got the problems fixed. But I wanted to offer you a possible solution.
@Pacerino line 93 gives an error:
$encodedSignature = $request->header('x-postal-signature');
This is the error:
mautic.CRITICAL: Uncaught PHP Exception Symfony\Component\Debug\Exception\FatalThrowableError: "Attempted to call an undefined method named "header" of class "Symfony\Component\HttpFoundation\Request"." ...
I changed the line 93 to:
$encodedSignature = $request->headers->get('X-POSTAL-SIGNATURE', '');
And I get the error:
Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\HttpException: "Wrong signature" ...
I do not know further... It should work, but I do not understand why it does not.
@IonutOjicaDE
Thank you for the fix with the header! I'll push it to the repo in a minute.
For the signature it was my fault. The webhook_signing_key
is the part from the DKIM.
So instead of generating the PublicKey with OpenSSL, you can take the part from the dkim.
postal default-dkim-record
p=
partI've ran a small test and it seems to work.
More to Read: https://github.com/postalserver/postal/issues/432#issuecomment-404172757 https://github.com/postalserver/postal/issues/432#issuecomment-353143578
Great ! Super ! I implement it and it works indeed :) I am so glad. You are amazing !!! I also searched Postal forum, but not found or did not understand.
Now it should be implemented also here, in the github code.
Should it be before or after the issue is closed? For me, the issue is successfully solved.
Hi, Im using Postal 3.3.3
and Mautic 4.4.12
and I haven't been able to make the bounce emails work.
Im not sure what additional configuration I need to do to make it work.
Can you use this one, as I have made the proper changes as I use the plugin:
Hi, I just cloned your fork onto Mautic and it installed Postal - api
but on your README file you mentioned that it suppose to be SMTP.
Also, as soon as I provided the API key and click on save, it breaks Mautic.
What can I do?
Thanks again for the time helping me.
I have tried to install this plugin but as soon as I do mautic:plugins:reload mautic breaks There are too many redirect in the web server, trying to check logs I can't spot any interesting errors...just a lot of http requests
Mautic 4.4.12 Postal 3.3.4
any idea ?
The MessageDeliveryFailed and MessageBounced Webhooks (actually no Webhook) are recognized by the plugin.
I suppose that the actual Postal version 2.1.4 is using another encription and the function does not process the encription right:
public function processCallbackRequest(Request $request): void