mirror of
https://github.com/freescout-helpdesk/freescout.git
synced 2025-02-01 04:21:39 +01:00
Allow to add custom headers to outgoing emails via APP_CUSTOM_MAIL_HEADERS env variable - closes #2546
This commit is contained in:
parent
a830e0440b
commit
542646e71a
@ -19,6 +19,9 @@ APP_URL=https://example.com
|
||||
# (access to freescout.net is required to obtain official modules)
|
||||
#APP_PROXY=
|
||||
|
||||
# Custom headers to add to all outgoing emails.
|
||||
#APP_CUSTOM_MAIL_HEADERS="IsTransactional:True;X-Custom-Header:value"
|
||||
|
||||
# Timezones: https://github.com/freescout-helpdesk/freescout/wiki/PHP-Timezones
|
||||
# Comment it to use default timezone from php.ini
|
||||
#APP_TIMEZONE=Europe/London
|
||||
|
@ -32,6 +32,8 @@ class Alert extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
\MailHelper::prepareMailable($this);
|
||||
|
||||
$subject = '['.\Config::get('app.name').'] ';
|
||||
if (!empty($this->title)) {
|
||||
$subject .= $this->title;
|
||||
|
@ -44,6 +44,8 @@ class AutoReply extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
\MailHelper::prepareMailable($this);
|
||||
|
||||
$view_params = [];
|
||||
|
||||
// Set headers
|
||||
|
@ -26,6 +26,8 @@ class PasswordChanged extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
\MailHelper::prepareMailable($this);
|
||||
|
||||
$message = $this->subject(__('Password Changed'))
|
||||
->view('emails/user/password_changed')
|
||||
->text('emails/user/password_changed_text');
|
||||
|
@ -64,6 +64,8 @@ class ReplyToCustomer extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
\MailHelper::prepareMailable($this);
|
||||
|
||||
// Set Message-ID
|
||||
// Settings via $this->addCustomHeaders does not work
|
||||
$new_headers = $this->headers;
|
||||
|
@ -23,6 +23,8 @@ class Test extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
\MailHelper::prepareMailable($this);
|
||||
|
||||
$this->withSwiftMessage(function ($swiftmessage) {
|
||||
$headers = $swiftmessage->getHeaders();
|
||||
$headers->addTextHeader('X-FreeScout-Mail-Type', 'test.mailbox');
|
||||
|
@ -25,6 +25,8 @@ class UserEmailReplyError extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
\MailHelper::prepareMailable($this);
|
||||
|
||||
return $this->subject(__('Unable to process your update'))
|
||||
->view('emails/user/email_reply_error');
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ class UserInvite extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
\MailHelper::prepareMailable($this);
|
||||
|
||||
$message = $this->subject(__('Welcome to :company_name!', ['company_name' => Option::getCompanyName()]))
|
||||
->view('emails/user/user_invite')
|
||||
->text('emails/user/user_invite_text');
|
||||
|
@ -70,6 +70,8 @@ class UserNotification extends Mailable
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
\MailHelper::prepareMailable($this);
|
||||
|
||||
// Set Message-ID
|
||||
// Settings via $this->addCustomHeaders does not work
|
||||
$new_headers = $this->headers;
|
||||
|
@ -806,6 +806,32 @@ class Mail
|
||||
}
|
||||
}
|
||||
|
||||
public static function prepareMailable($mailable)
|
||||
{
|
||||
$custom_headers_str = config('app.custom_mail_headers');
|
||||
|
||||
if (empty($custom_headers_str)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$custom_headers = explode(';', $custom_headers_str);
|
||||
|
||||
$mailable->withSwiftMessage(function ($swiftmessage) use ($custom_headers) {
|
||||
$headers = $swiftmessage->getHeaders();
|
||||
|
||||
foreach ($custom_headers as $custom_header) {
|
||||
$header_parts = explode(':', $custom_header);
|
||||
|
||||
$header_name = trim($header_parts[0] ?? '');
|
||||
$header_value = trim($header_parts[1] ?? '');
|
||||
if ($header_name && $header_value) {
|
||||
$headers->addTextHeader($header_name, $header_value);
|
||||
}
|
||||
}
|
||||
return $swiftmessage;
|
||||
});
|
||||
}
|
||||
|
||||
// public static function oauthGetProvider($provider_code, $params)
|
||||
// {
|
||||
// $provider = null;
|
||||
|
@ -366,6 +366,14 @@ return [
|
||||
*/
|
||||
'proxy' => env('APP_PROXY', ''),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Custom headers to add to all outgoing emails.
|
||||
| https://github.com/freescout-helpdesk/freescout/issues/2546#issuecomment-1380414908
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
'custom_mail_headers' => env('APP_CUSTOM_MAIL_HEADERS', ''),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Autoloaded Service Providers
|
||||
|
Loading…
x
Reference in New Issue
Block a user