laravel-mailbox icon indicating copy to clipboard operation
laravel-mailbox copied to clipboard

Incoming "to" not working

Open vmitchell85 opened this issue 6 years ago • 6 comments

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: [email protected]  
[2019-02-19 11:34:57] local.DEBUG: array (
)  
[2019-02-19 11:34:57] local.DEBUG: [email protected]  
[2019-02-19 11:34:57] local.DEBUG: =====================================  
[2019-02-19 11:38:10] local.DEBUG: [email protected]  
[2019-02-19 11:38:10] local.DEBUG: array (
)  
[2019-02-19 11:38:10] local.DEBUG: [email protected]  
[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 [email protected]

vmitchell85 avatar Feb 19 '19 11:02 vmitchell85

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('[email protected]', Email::class);

It works just fine.

oliverbj avatar Mar 02 '19 14:03 oliverbj

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 avatar Mar 12 '19 03:03 vmitchell85

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.

vmitchell85 avatar Mar 12 '19 12:03 vmitchell85

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 avatar Oct 26 '20 11:10 Noogic

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

This also seems to work

Noogic avatar Oct 27 '20 09:10 Noogic

Any news?

wolf-ingelheim avatar Apr 13 '22 14:04 wolf-ingelheim