2017 © Pedro Peláez
 

library slack-laravel-mail

Laravel Mail driver that delivers mail to your Slack server

image

timfeid/slack-laravel-mail

Laravel Mail driver that delivers mail to your Slack server

  • Wednesday, July 18, 2018
  • by timfeid1
  • Repository
  • 1 Watchers
  • 1 Stars
  • 109 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 4 % Grown

The README.md

alt text, (*1)

Set up

Installation

composer require timfeid/slack-laravel-mail, (*2)

Add TimFeid\SlackLaravelMail\SlackMailServiceProvider::class, to your providers list in your app.php config., (*3)

    TimFeid\SlackLaravelMail\SlackMailServiceProvider::class,

Config

Add the following config to your services.php config file., (*4)

    'slackmail' => [
        // The endpoint to your webhook
        'endpoint' => env('SLACKMAIL_ENDPOINT', 'https://hooks.slack.com/services/..../....'),
        // The driver for which you would like to store emails
        // Drivers are 'cache' and 'file' for now
        'driver' => env('SLACKMAIL_DRIVER', 'cache'),
        // Cache settings, will always use your default cache driver for now
        'cache' => [
            // Remove if you would not like to use cache()->tags()
            'tag' => 'slack-mail',
            // Time you want to keep emails for in minutes
            'ttl' => 60,
        ],
        'file' => [
            // File location you would like to save your emails
            'location' => storage_path('/mail'),
        ],
        // From user for your Slack message
        'from' => 'Emails',
        // Channel you'd like to send your messages to
        // @username to send private messages from @Slackbot
        'channel' => env('SLACKMAIL_TO', '#emails'),
        // Fields you would like to show up in your message
        'fields' => [
            'subject',
            'to',
            'cc',
            'bcc',
            'from',
            'attachments',
        ],
    ],

Dot File (.env)

As you can probably tell, .env is encouraged for a per-environment setup, (*5)

    SLACKMAIL_ENDPOINT="https://hooks.slack.com/services..."
    SLACKMAIL_DRIVER="cache"
    SLACKMAIL_TO="@username"

    MAIL_DRIVER="slack" # Activate slackmail as your mail driver

Route

Add this route to your routes file. The route can be set up however you'd like, but it must have slackmail as the name ->name('slackmail'), (*6)

    if (!app()->environment('production')) {
        Route::get('/slack-mail/{name}', '\TimFeid\SlackLaravelMail\Controllers\SlackMailController@slackMail')
            ->name('slackmail');
    }

Extending the fields

You'll want to create service provider that extends SlackMailServiceProvider and overwrite the registerSlackFields method., (*7)

<?php

namespace App\Providers;

use App\Services\Slack\SlackFields;
use TimFeid\SlackLaravelMail\SlackMailServiceProvider as BaseProvider;

class SlackMailServiceProvider extends BaseProvider
{
    public function registerSlackFields()
    {
        $this->app->singleton('slackmail.fields', SlackFields::class);
    }
}

Example SlackFields class

<?php

namespace App\Services\Slack;

use TimFeid\SlackLaravelMail\SlackFields as BaseSlackFields;

class SlackFields extends BaseSlackFields
{
    public function buildSendgridField()
    {
        return [
            'title' => 'Sendgrid Headers',
            'value' => '```'.json_encode([
                'categories' => $this->message->getCategories(),
                'custom_args' => $this->message->getArguments(),
            ], JSON_PRETTY_PRINT).'```',
        ];
    }
}

The Versions

18/07 2018

dev-master

9999999-dev

Laravel Mail driver that delivers mail to your Slack server

  Sources   Download

MIT

The Requires

 

by Tim Feid

18/07 2018

2.0.1

2.0.1.0

Laravel Mail driver that delivers mail to your Slack server

  Sources   Download

MIT

The Requires

 

by Tim Feid

18/01 2018

2.0.0

2.0.0.0

Laravel Mail driver that delivers mail to your Slack server

  Sources   Download

MIT

The Requires

 

by Tim Feid

06/11 2017

1.1.0

1.1.0.0

Laravel Mail driver that delivers mail to your Slack server

  Sources   Download

MIT

The Requires

 

by Tim Feid

06/11 2017

1.1.0.x-dev

1.1.0.9999999-dev

Laravel Mail driver that delivers mail to your Slack server

  Sources   Download

MIT

The Requires

 

by Tim Feid

16/05 2017

1.0.0

1.0.0.0

Laravel Mail driver that delivers mail to your Slack server

  Sources   Download

MIT

The Requires

 

by Tim Feid