Sep 8, 2020
0
Level 4
Lumen Mailable ShouldQueue not queuing
i am working on Lumen 6.0 and i have come across a very strange issue.
i am trying to send the emails on mailable queue using ShouldQueue on my mailable class, but it would seem that mails are going normally not sending through a queue, as ShouldQueue should do automatically for all emails. i am using eloquent observers to detect events and then send emails
my Observer
use App\Contact;
use App\Mail\ContactMail;
use Illuminate\Support\Facades\Mail;
class ContactObserver
{
/**
* Handle the Account "created" event.
*
* @param Contact $contact
* @return void
*/
public function created(Contact $contact)
{
if (env('MAIL_ENABLED')) // boolean value in .env
Mail::to(['[email protected]'])->send(new ContactMail($contact));
}
}
my Mailable
use App\Contact;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ContactMail extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
public $contact;
/**
* Create a new message instance.
*
* @param Contact $contact
*/
public function __construct(Contact $contact)
{
$this->contact = $contact;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->subject("Contact - " . config('app.name'))->from(config('mail.from'))->markdown('emails.contact.new');
}
}
my ServiceProvider
use App\Contact;
use App\Observers\ContactObserver;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
* @throws BindingResolutionException
*/
public function boot()
{
Schema::defaultStringLength(191);
$this->app->make('queue'); // without this i get >> Argument 1 passed to Illuminate\Mail\Mailable::queue() must be an instance of Illuminate\Contracts\Queue\Factory, null given, called in /var/www/html/vendor/illuminate/mail/Mailer.php on line 388
Contact::observe(ContactObserver::class);
}
}
Please or to participate in this conversation.