beyondcode / laravel-mailbox

Catch incoming emails in your Laravel application
https://beyondco.de/docs/laravel-mailbox/getting-started/introduction
MIT License
1.04k stars 127 forks source link

Update MailCare Request #95

Closed mailcare closed 1 year ago

mailcare commented 2 years ago

The MailCare driver doesn't work.

This PR will fix the issue.

joelharkes commented 2 years ago

@mailcare is this still an issue? i can fix it in my fork: https://github.com/joelharkes/laravel-mailbox

eXorus commented 2 years ago

Yes still an issue, but the PR are not merged. I'm not sure Laravel mailbox is still used.

joalea commented 1 year ago

Please accept this PR! 👍

joelharkes commented 1 year ago

@joalea and @siebsie23 Im trying to solve it but i dont understand how this code would solve it.

When i read the documentation: https://mailcare.docs.apiary.io/#reference/0/automations-resource/automation-webhook

it suggests getting the email from data.sender.email not from php://input Do i have the right documentation?

siebsie23 commented 1 year ago

@joelharkes To be honest I'm not sure. I just blindly merged it into my fork. But in theory the php://input should just get the full raw body of the email right?

joelharkes commented 1 year ago

As far as i understand, this would store the complete JSON in the message field in the database, but not the actual EML file/ email file. Im looking at how to get this but i do not see, even the get email api call seems to have no contents? you can only download attachements?

see: https://mailcare.docs.apiary.io/#reference/0/email-resource/get-an-email

joelharkes commented 1 year ago

Instead it seems like you have to checkbox the "Post the raw, full MIME message": https://github.com/mailcare/mailcare

image
eXorus commented 1 year ago

Yes it works only if you check the checkbox "Post the raw, full MIME message".

A new PR has been created: https://github.com/beyondcode/laravel-mailbox/pull/114 and it has been fully tested.

joelharkes commented 1 year ago

@eXorus actually php://input would have been required to get the full http headers and body. But that for example does not work with Laravel Octane.

Im not sure there is a proper solution for this. Only maybe this would work: https://stackoverflow.com/a/23447426/1275832

eXorus commented 1 year ago

But you don't need to have the http headers, you only need the email body and Laravel mailbox will decode the email for you. It's exactly how the other drivers works: postmark with the rawemail attribute, sendgrid with the email attribute.

joelharkes commented 1 year ago

@eXorus the HTTP headers are equal to the Email headers, it contains who send the email and who received it ETC.

So they are picked up as HTTP headers and you will only get the Email HTML body and miss all the email context information

eXorus commented 1 year ago

Sorry I don't understand, the other drivers works the same they send more information in a Json properties like subject or to but they are not used by laravel mailbox because Laravel mailbox use only the raw email (with email headers and bodies) to decode the subject...

So same for MailCare but I don't send the decoded subject, because laravel mailbox don't need it.

From a user point of view you will have all the emails headers and all the emails bodies.

joelharkes commented 1 year ago

No, the email headers are filtered out by PHP (as they are identical as HTTP header structure they are seen as HTTP headers).

I did some testing locally. When I have more time I'll make a proper PR to make it work in any circumstance although maybe not the ideal solution.

joelharkes commented 1 year ago

Found proper solution as i could get: doing $request->__toString() It does add extra HTTP requests, maybe good fallback for php://input

image
joelharkes commented 1 year ago

@eXorus i was wrong it, does seem to POST the whole email message in the HTTP Body (it doesn not skip the HTTP request)

https://github.com/mailcare/mailcare/blob/7f9973e1dfaed42811fd64b9a7c81fc0e6e47230/app/Listeners/AutomationListener.php#L83

joelharkes commented 1 year ago

@eXorus my Fork supports it now with proper testing also: https://packagist.org/packages/joelharkes/laravel-mailbox