laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.2k stars 10.89k forks source link

Feature: Adding Cc and Bcc to Notification Emails in MailMessage #15694

Closed mtpultz closed 7 years ago

mtpultz commented 7 years ago

Notification emails though you can set to to be an array of email addresses MailMessage is missing cc. I can see in MailChannel that bcc exists if multiple recipients, but it would be nice to allow for direct whitelisting and blacklisting directly instead of it being assumed. In some cases you would want to have each individual mailed with each of the recipients known.

Steps To Reproduce:

N/A

themsaid commented 7 years ago

If you set to array the bcc attribute will be used, but yeah there's no cc.

However you can use a Mailable instead:

public function toMail($notifiable)
{
      return (new \App\Mail\OrderShipped($this->order))->to($notifiable->routeNotificationFor('mail'))->cc(...);
}
mtpultz commented 7 years ago

Nice, I didn't know you could use Mailables in Notifications they seem to be documented as two different services so I assumed I would be customizing the MailMessage class, and overwriting the MailChannel. This isn't even mentioned in the Laracast videos, which also make it sound like they are separate entities.

Thanks @themsaid

themsaid commented 7 years ago

It was added a few days ago, guess no one PRed a doc update :)

mtpultz commented 7 years ago

I noticed you focused on the existence of Bcc, but I also mentioned I noticed if it was an array it would Bcc all recipients. In some cases you don't want to Bcc everyone.

themsaid commented 7 years ago

Well I think it's just a convenient, you can always use a Mailable which will give you more flexibility.

mtpultz commented 7 years ago

Thanks @themsaid will do :)

minkbear commented 7 years ago

FYI

cc and bcc are in MailMessage since laravel v5.3.22 (2016-11-01)

ilarioengler commented 7 years ago

@minkbear cc yes, but bcc not

minkbear commented 7 years ago

@iangcarroll OH yes, you are right.

vedmant commented 7 years ago

Hm, I don't see anything like this in Laravel 5.4, MailMessage and SimpleMessage don't have either "to", "cc" or "bcc" methods.

RamiJabr commented 7 years ago

Hi guys!

Maybe just a hotfix, until the notification uses some config value for bcc recipients. Easiest way I think will be to set up an EventListener. Something like that

namespace Tenmedia\Example\Listeners;

use Illuminate\Mail\Events\MessageSending;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class MessageSendingListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  MessageSending  $event
     * @return void
     */
    public function handle(MessageSending $event)
    {
        $event->message->addBcc('bcc@example.com');
    }
}