Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InboundEmail->forward not working Laravel 10 #122

Open
mathewparet opened this issue Feb 19, 2024 · 4 comments
Open

InboundEmail->forward not working Laravel 10 #122

mathewparet opened this issue Feb 19, 2024 · 4 comments

Comments

@mathewparet
Copy link

I get the below error when trying to forward email.

Error:

Symfony\Component\Mime\Message::setBody(): Argument #1 ($body) must be of type ?Symfony\Component\Mime\Part\AbstractPart, string given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php on line 23 {"exception":"[object] (TypeError(code: 0): Symfony\\Component\\Mime\\Message::setBody(): Argument #1 ($body) must be of type ?Symfony\\Component\\Mime\\Part\\AbstractPart, string given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php on line 23 at /var/www/html/vendor/symfony/mime/Message.php:45)

Code:

 Mailbox::catchall(InboundEmail $inboundEmail)
{
$inboundEmail->forward('someone@example.com');
}

Looks like there was a similar issue with replies to Laravel 9 - https://github.com/beyondcode/laravel-mailbox/pull/103
@rtconner
Copy link

Is this project maintained?

I want to use it, but ... cannot use it if its not maintained.

@hrsa
Copy link

hrsa commented May 7, 2024

I had the same issue. It looks like Symfony mailer changed syntaxis (https://laracasts.com/discuss/channels/laravel/body-must-be-of-type-mimepartabstractpart-string-given).

@rtconner @mathewparet in case you haven't found a solution yet - here is what i did. It kinda works like a forward solution...

public function forwardToAdmin(InboundEmail $email): void
    {
        Mail::to(config('app.admin.email'))->send(new ForwardEmail($email));
    }
class ForwardEmail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(public InboundEmail $inboundEmail)
    {
    }

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: "FROM: " . $this->inboundEmail->fromName() . " (" . $this->inboundEmail->from() . ") - " . $this->inboundEmail->subject(),
        );
    }

    public function content(): Content
    {
        return new Content(
            htmlString: $this->inboundEmail->html()
        );
    }

    public function attachments(): array
    {
        return $this->inboundEmail->attachments();
    }
}

@bardolf69
Copy link

bardolf69 commented May 24, 2024

Fix issues with forwarding emails since Laravel 9.0 #127

@bardolf69
Copy link

bardolf69 commented May 24, 2024

Now just need a maintainer to approve the pull request. in the interrim if you want to fix the code yourself you can go to vendor > beyondcode > laravel-mailbox > src > InboundEmail.php and find this section (line 168 in mine)

public function forward($recipients)
    {
        return Mail::send([], [], function ($message) use ($recipients) {
            $message->to($recipients)
                ->subject($this->subject())
                ->setBody($this->body(), $this->message()->getContentType());
        });
    }

and change to

public function forward($recipients)
    {
        return Mail::send([], [], function ($message) use ($recipients) {
            $message->to($recipients)
                ->subject($this->subject())
                ->text($this->text())
                ->html($this->html());
        });
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants