gsferro/servicemail

There is no license information available for the latest version (v1.1.1) of this package.

Service para envio via queue easy no Laravel

v1.1.1 2021-05-04 18:30 UTC

This package is auto-updated.

Last update: 2021-05-04 18:35:22 UTC


README

Service para envio de e-mail via queue easy no Laravel

Install via composer

composer require gsferro/servicemail

Configuração

  • Adicione o ServiceProvider em providers de app.php
/*
|---------------------------------------------------
| ServiceMail
|---------------------------------------------------
*/

\Gsferro\ServiceMail\Providers\ServiceMailServiceProvider::class,
  • Adicione em $listen o event em EventServiceProvider.php
/*
|---------------------------------------------------
| ServiceMail
|---------------------------------------------------
*/
 'Gsferro\ServiceMail\Events\MailerEvent' => [
    'Gsferro\ServiceMail\Listeners\MailerJobListener',
 ],
  • Publish config
php artisan vendor:publish --provider="Gsferro\ServiceMail\Providers\ServiceMailServiceProvider" --tag=config    

Uso

<?php   
    servicemail()->send(
        string $view,
        string $subject,
        string $to,
        $data,
        ?\DateTime $timeEvent = null,
        string $attach = null,
        $cc = null
    );
  • Gerar migration
  1. php artisan queue:table
  2. php artisan queue:failed-table

Alternativa ao mailtrap

  • set a variavel SERVICEMAIL_REDIRECT no .env ou dentro do config/servicemail.php para enviar o email para si como debug/teste

Usando database sqlite

  • Crie o banco local

touch database/database.sqlite

  • Publish Migrations em migrations/servicemail
php artisan vendor:publish --provider="Gsferro\ServiceMail\Providers\ServiceMailServiceProvider"  --tag=migrations
  • Altere o arquivo config/database.php
    'connections' => [
        'sqlite' => [
            'driver'                  => 'sqlite',
            'database'                => database_path( 'database.sqlite' ),
            'prefix'                  => '',
            'foreign_key_constraints' => env( 'DB_FOREIGN_KEYS', true ),
        ],
  • Altere o arquivo config/queue.php
     'connections' => [
         'sqlite' => [
             'connection'   => 'sqlite',
             'driver'       => 'database',
             'table'        => 'jobs',
             'queue'        => 'default',
             'retry_after'  => 90,
         ],
  • Altere o arquivo .env
QUEUE_CONNECTION="sqlite"

Ou coloque direto no arquivo config/queue.php

[
    'default' => "sqlite",
]

Rodar migrate

php artisan migrate --database=sqlite --path=database/migrations/jobs

Rodar queue

php artisan queue:work sqlite --tries=3
links úteis: