Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Custom Headers when sending mail via notification "MailMessage" #475

Closed
andrew-za opened this issue Mar 18, 2017 · 4 comments
Closed

Custom Headers when sending mail via notification "MailMessage" #475

andrew-za opened this issue Mar 18, 2017 · 4 comments

Comments

@andrew-za
Copy link

Laravel Version: 5.3.9
PHP Version: 7.0.10
Database Driver & Version: mysql 10.1.17-MariaDB
Description:

When sending a notification via mail, there is no way to add custom headers to it.

I understand notifications are meant to be simple messages, but for example, when using Mandrill you need to send a custom header if you want your messages to be sent through one of your subaccounts. This is impossible AFAICS for notification emails and that messes hard with my Mandrill account.

A similar function to the one on the Mailable class (withSwiftMessage) allowing to access the SwiftMessage would fix this.

Steps To Reproduce:

Try to attach custom headers when sending a notification via email.

@craigpaul
Copy link

craigpaul commented Mar 19, 2017

@andrew-za You can return a mailable from your notification and then in your mailable class you can add a public $callbacks property with an array of closures that access the \Swift_Message through that. Would that solve your problem? Ex.

public function __construct()
{
    $this->callbacks[] = function ($message) {
        $message->getHeaders()->addTextHeader('Header', 'Value');
    }
}

Those callbacks get run last in the mailing process.

@andrew-za
Copy link
Author

Thanks craig - that seems to be the only way.

@debbiev
Copy link

debbiev commented Sep 19, 2018

I had to add parenthesis (); to the above code to get it to work:

public function __construct()
{
    $this->callbacks[] =( function ($message) {
        $message->getHeaders()->addTextHeader('Header', 'Value');
    });
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants