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

Incoming "to" not working #29

Open vmitchell85 opened 5 years ago

vmitchell85 commented 5 years ago

I'm trying to get this setup using an incoming "to" as such:

Mailbox::to('{uuid}@mydomain.com', DefaultMailbox::class);

The mailbox was never matching, so I created a catch all to test it out:

Mailbox::catchAll(CatchAllMailbox::class);

The catch all seems to be working but the email does not seem to be parsed correctly.

Contents of CatchAllMailbox.php

<?php

namespace App\Mailboxes;

use BeyondCode\Mailbox\InboundEmail;

class CatchAllMailbox
{
    public function __invoke(InboundEmail $email)
    {
        logger($email->id());
        logger($email->to());
        logger($email->from());
        logger($email->subject());
        logger('=====================================');
    }
}

Log Result

[2019-02-19 11:34:57] local.DEBUG: 20190219113456.1.C52A0016EF9E568D@mydomain.com  
[2019-02-19 11:34:57] local.DEBUG: array (
)  
[2019-02-19 11:34:57] local.DEBUG: postmaster@mydomain.com  
[2019-02-19 11:34:57] local.DEBUG: =====================================  
[2019-02-19 11:38:10] local.DEBUG: 20190219112808.1.FA0D36529944A4DC@mydomain.com  
[2019-02-19 11:38:10] local.DEBUG: array (
)  
[2019-02-19 11:38:10] local.DEBUG: postmaster@mydomain.com  
[2019-02-19 11:38:10] local.DEBUG: =====================================  

The to list seems to be empty, however if i take the stored message from the database and decode the base64 I can see the recipient field is set to c8896a6b-be27-49d3-afed-950a11540189@mydomain.com

oliverbj commented 5 years ago

Having the same problem.

I have set up the AppSerivceProvider like this:

  Mailbox::to('{token}@in.myapp.com', Email::class);

However nothing is stored, and the Email class is never fired. If I change it to:

  Mailbox::from('myemail@hotmail.com', Email::class);

It works just fine.

vmitchell85 commented 5 years ago

I've done a bunch of testing and it seems the issue has to do with the URL being used for the incoming emails that is referenced in #28.

It seems that Mailgun is sending a different style of information when an email comes in via email than it does even using their Send A Sample POST feature on their website.

I tried to modify the URL in BeyondCode\Mailbox\Drivers\Mailgun.php to not end with mime with no luck, I keep getting a 302 redirect instead of a 200 for some reason.

I'm going to keep hunting but maybe this helps further narrow down the issue.

vmitchell85 commented 5 years ago

I've determined the redirect is due to the validator. The non-mime URLs/Mailgun POSTs doesn't include body-mime. Changing this to use body-html did not work.

It seems to me a new mailgun non-mime driver should probably be created in order to work properly. So this issue could probably be combined with #28.

Noogic commented 4 years ago

I have the same issue using Postmark. It looks like the library is not parsing correctly the message headers.

I've come with a solution (which probably needs some testing with emails sent from different providers)

private function getTo(string $raw): string
    {
        $matches = [];
        preg_match("/\[\"To\",\"(.*?)\"\]/", $raw, $matches);

        return $matches[1];
    }

So you can get the to header using: $this->getTo(json_encode($email->message()->getRawHeaders()))

Anyway, I'll keep digging it to see if I get to the source of the problem, because if the other headers are working, this should too.

Noogic commented 4 years ago

$email->message()->getHeader('To')->getValue()

This also seems to work

wolf-ingelheim commented 2 years ago

Any news?