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

Doesn't work with ShouldQueue contract on mailable #38

Closed
joostdebruijn opened this issue Jan 16, 2023 · 5 comments · Fixed by #39
Closed

Doesn't work with ShouldQueue contract on mailable #38

joostdebruijn opened this issue Jan 16, 2023 · 5 comments · Fixed by #39
Labels
bug Something isn't working

Comments

@joostdebruijn
Copy link

It looks like this package doesn't work with the new style mailables as introduced in laravel/framework#44462. When using a new style mailable, the following error occurs: Xammie\Mailbook\ResolvedMail::__construct(): Argument #1 ($message) must be of type Symfony\Component\Mime\Email, null given.

You can test it by replacing App\Mail\MailbookMail by this:

<?php

namespace App\Mail;

use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;

class MailbookMail extends Mailable
{
    /**
     * Get the message envelope.
     *
     * @return \Illuminate\Mail\Mailables\Envelope
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Welcome to mailbook!'
        );
    }

    /**
     * Get the message content definition.
     *
     * @return \Illuminate\Mail\Mailables\Content
     */
    public function content(): Content
    {
        return new Content(
            markdown: $this->getView('mail.mailbook')
        );
    }
}
@Xammie Xammie added the bug Something isn't working label Jan 16, 2023
@Xammie
Copy link
Owner

Xammie commented Jan 16, 2023

Thanks for your report, I'm going to look into it.

@Xammie
Copy link
Owner

Xammie commented Jan 16, 2023

@joostdebruijn Your problem seems to be in the content function. The method getView() does not exist. The following works for me.

public function content(): Content
{
    return new Content(
-       markdown: $this->getView('mail.mailbook')
+       markdown: 'mail.mailbook'
    );
}

In case this does not work could you supply more context like OS, PHP version, Laravel version etc?

@Xammie Xammie closed this as completed Jan 16, 2023
@joostdebruijn
Copy link
Author

@Xammie Thanks for looking at this issue, you're right: the getView() function was not available in the example, it was just a copy/paste mistake from my side.

However, the issue still persists and I found out that the issue happens when using the ShouldQueue contract on the mailable. This is a tested and reproducable example of my issue ("Xammie\Mailbook\ResolvedMail::__construct(): Argument #1 ($message) must be of type Symfony\Component\Mime\Email, null given"):

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class MailbookMail extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    /**
     * Get the message envelope.
     *
     * @return \Illuminate\Mail\Mailables\Envelope
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Welcome to mailbook!'
        );
    }

    /**
     * Get the message content definition.
     *
     * @return \Illuminate\Mail\Mailables\Content
     */
    public function content(): Content
    {
        return new Content(
            markdown: 'mail.mailbook'
        );
    }
}

When removing implements ShouldQueue the viewer works again.

@joostdebruijn joostdebruijn changed the title Doesn't work with the alternative mailable syntax Doesn't work with ShouldQueue contract on mailable Jan 16, 2023
@Xammie Xammie reopened this Jan 16, 2023
Xammie added a commit that referenced this issue Jan 17, 2023
@Xammie
Copy link
Owner

Xammie commented Jan 17, 2023

Thanks again for reporting. This has been fixed in version 1.5.3.

@daniel-de-wit
Copy link
Contributor

In my case the esign/laravel-email-whitelisting package caused the same error message. Even though it was disabled by setting EMAIL_WHITELISTING_ENABLED=false..

The event dispatcher caused a halt. Can't figure out why.

(i know this is not the concern of this wonderful package, but it might save other a few hours of debugging)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants