Open mathewparet opened 9 months ago
Is this project maintained?
I want to use it, but ... cannot use it if its not maintained.
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();
}
}
Fix issues with forwarding emails since Laravel 9.0 https://github.com/beyondcode/laravel-mailbox/pull/127
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());
});
}
@bardolf69 Thanks for posting the solution. My 2cs:
We should create a new model that extends InboundEmail
and then register it in config/mailbox.php
:
App\Models'InboundEmail:
<?php
namespace App\Models;
use Illuminate\Support\Facades\Mail;
use BeyondCode\Mailbox\InboundEmail as BaseModel;
class InboundEmail extends BaseModel
{
public function forward($recipients)
{
return Mail::send([], [], function ($message) use ($recipients) {
$message->to($recipients)
->subject($this->subject())
->text($this->text())
->html($this->html());
});
}
}
config/mailbox.php:
'model' => \App\Models\InboundEmail::class,
I get the below error when trying to forward email.
Error:
Code: