Queued mails don't work:
[2018-12-07 06:08:19] local.ERROR: Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Mail\Mailer] is not instantiable while building [Illuminate\Notifications\Channels\MailChannel]. in ../vendor/illuminate/container/Container.php:945
Put a Mailable or Mail Notification into the queue.
Have to rise this problem again as it still takes place in the latest version of Lumen.
The problem can be bypassed by adding:
$app->alias('mailer', \Illuminate\Contracts\Mail\Mailer::class);
into the bootstrap/app.php file, but @taylorotwell said it should be solved in the framework itself.
Please, don't close this issue until it's solved.
https://github.com/laravel/lumen-framework/issues/503
https://github.com/laravel/lumen-framework/issues/590
https://github.com/laravel/lumen-framework/issues/77
https://github.com/laravel/lumen-framework/issues/221
https://github.com/laravel/lumen-framework/issues/634
You're sure you've followed all steps from https://lumen.laravel.com/docs/5.7/mail ?
I'll need more info and/or code to debug this further. Please post relevant code like models, jobs, commands, notifications, events, listeners, controller methods, routes, etc. You may use https://paste.laravel.io to post larger snippets or just reply with shorter code snippets. Thanks!
Yes (I wrote it).
Mail is not sent when is queued in any cases. It's simple to reproduce:
// User.php
namespace Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class User extends Model
{
use Notifiable;
// Notifications/SendVerificationEmail.php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class SendVerificationEmail extends Notification implements ShouldQueue
{
use Queueable;
// UserController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Auth;
use App\User;
use App\Notifications\SendVerificationEmail;
class UserController extends ApiController
{
public function create(Request $request)
{
// ...
$user->notify(new SendVerificationEmail);
And try to run it through the queue:
php artisan queue:work
Queue task will fail. Logs:
[2018-12-07 06:08:19] local.ERROR: Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Mail\Mailer] is not instantiable while building [Illuminate\Notifications\Channels\MailChannel]. in ../vendor/illuminate/container/Container.php:945
Did some digging into this and I believe you always will have to do this. In Laravel it's done for you in the registerCoreContainerAliases method of the Application class:
But because the mailer component doesn't comes included with Lumen this isn't done in Lumen's Application class. It seems it's best to add this to the Lumen docs itself. I'll send in a PR.
Sent in a PR: https://github.com/laravel/lumen-docs/pull/162
Finally I've seen it solved. Thanks, @driesvints . Great job!
Most helpful comment
Sent in a PR: https://github.com/laravel/lumen-docs/pull/162