This commit is contained in:
paulwer 2023-12-21 16:59:39 +01:00
parent 3206e46349
commit 507cdafa26
9 changed files with 21540 additions and 21539 deletions

View File

@ -453,10 +453,6 @@ class CompanySettings extends BaseSettings
public $brevo_secret = '';
public $brevo_domain = '';
public $brevo_endpoint = 'api.mailgun.net'; //api.eu.mailgun.net
public $auto_bill_standard_invoices = false;
public $email_alignment = 'center'; // center , left, right
@ -511,7 +507,6 @@ class CompanySettings extends BaseSettings
'default_expense_payment_type_id' => 'string',
'e_invoice_type' => 'string',
'mailgun_endpoint' => 'string',
'brevo_endpoint' => 'string',
'client_initiated_payments' => 'bool',
'client_initiated_payments_minimum' => 'float',
'sync_invoice_quote_columns' => 'bool',
@ -529,7 +524,6 @@ class CompanySettings extends BaseSettings
'mailgun_secret' => 'string',
'mailgun_domain' => 'string',
'brevo_secret' => 'string',
'brevo_domain' => 'string',
'send_email_on_mark_paid' => 'bool',
'vendor_portal_enable_uploads' => 'bool',
'besr_id' => 'string',

View File

@ -213,7 +213,7 @@ class SettingsData
public bool $show_accept_quote_terms = false; //@TODO ben to confirm
public string $email_sending_method = 'default'; // enum 'default', 'gmail', 'office365', 'client_postmark', 'client_mailgun' , 'brevo_mailgun' //@implemented
public string $email_sending_method = 'default'; // enum 'default', 'gmail', 'office365', 'client_postmark', 'client_mailgun' , 'client_brevo' //@implemented
public string $gmail_sending_user_id = '0'; //@implemented
@ -435,10 +435,6 @@ class SettingsData
public string $brevo_secret = '';
public string $brevo_domain = '';
public string $brevo_endpoint = 'api.mailgun.net'; // api.eu.mailgun.net
public bool $auto_bill_standard_invoices = false;
public string $email_alignment = 'center'; // center, left, right

View File

@ -64,8 +64,6 @@ class NinjaMailerJob implements ShouldQueue
protected $client_brevo_secret = false;
protected $client_brevo_domain = false;
public function __construct(NinjaMailerObject $nmo, bool $override = false)
{
$this->nmo = $nmo;
@ -137,7 +135,7 @@ class NinjaMailerJob implements ShouldQueue
}
if ($this->client_brevo_secret) {
$mailer->brevo_config($this->client_brevo_secret, $this->client_brevo_domain, $this->nmo->settings->brevo_endpoint);
$mailer->brevo_config($this->client_brevo_secret);
}
$mailer
@ -335,8 +333,6 @@ class NinjaMailerJob implements ShouldQueue
$this->client_brevo_secret = false;
$this->client_brevo_domain = false;
//always dump the drivers to prevent reuse
app('mail.manager')->forgetMailers();
}
@ -406,9 +402,8 @@ class NinjaMailerJob implements ShouldQueue
*/
private function setBrevoMailer()
{
if (strlen($this->nmo->settings->brevo_secret) > 2 && strlen($this->nmo->settings->brevo_domain) > 2) {
if (strlen($this->nmo->settings->brevo_secret) > 2) {
$this->client_brevo_secret = $this->nmo->settings->brevo_secret;
$this->client_brevo_domain = $this->nmo->settings->brevo_domain;
} else {
$this->nmo->settings->email_sending_method = 'default';
return $this->setMailDriver();

View File

@ -28,6 +28,8 @@ use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;
use Symfony\Component\Mailer\Bridge\Brevo\Transport\BrevoTransportFactory;
use Symfony\Component\Mailer\Transport\Dsn;
class AppServiceProvider extends ServiceProvider
{
@ -113,15 +115,24 @@ class AppServiceProvider extends ServiceProvider
return $this;
});
Mailer::macro('brevo_config', function (string $secret, string $domain, string $endpoint = 'api.mailgun.net') {
Mail::extend('brevo', function () {
return (new BrevoTransportFactory)->create(
new Dsn(
'brevo+api',
'default',
config('services.brevo.key')
)
);
});
Mailer::macro('brevo_config', function (string $key) {
// @phpstan-ignore /** @phpstan-ignore-next-line **/
Mailer::setSymfonyTransport(app('mail.manager')->createSymfonyTransport([
'transport' => 'brevo',
'secret' => $secret,
'domain' => $domain,
'endpoint' => $endpoint,
'scheme' => config('services.brevo.scheme'),
]));
Mail::setSymfonyTransport((new BrevoTransportFactory)->create(
new Dsn(
'brevo+api',
'default',
$key
)
));
return $this;
});

View File

@ -57,10 +57,6 @@ class AdminEmail implements ShouldQueue
protected ?string $client_brevo_secret = null;
protected ?string $client_brevo_domain = null;
protected ?string $client_brevo_endpoint = null;
private string $mailer = 'default';
public Mailable $mailable;
@ -140,7 +136,7 @@ class AdminEmail implements ShouldQueue
}
if ($this->client_brevo_secret) {
$mailer->brevo_config($this->client_brevo_secret, $this->client_brevo_domain, $this->client_brevo_endpoint);
$mailer->brevo_config($this->client_brevo_secret);
}
/* Attempt the send! */
@ -254,7 +250,7 @@ class AdminEmail implements ShouldQueue
}
/* GMail users are uncapped */
if (in_array($this->email_object->settings->email_sending_method, ['gmail', 'office365', 'client_postmark', 'client_mailgun'])) {
if (in_array($this->email_object->settings->email_sending_method, ['gmail', 'office365', 'client_postmark', 'client_mailgun', 'client_brevo'])) {
return false;
}
@ -402,10 +398,6 @@ class AdminEmail implements ShouldQueue
$this->client_brevo_secret = null;
$this->client_brevo_domain = null;
$this->client_brevo_endpoint = null;
//always dump the drivers to prevent reuse
app('mail.manager')->forgetMailers();
}
@ -476,10 +468,8 @@ class AdminEmail implements ShouldQueue
*/
private function setBrevoMailer()
{
if (strlen($this->email_object->settings->brevo_secret) > 2 && strlen($this->email_object->settings->brevo_domain) > 2) {
if (strlen($this->email_object->settings->brevo_secret) > 2) {
$this->client_brevo_secret = $this->email_object->settings->brevo_secret;
$this->client_brevo_domain = $this->email_object->settings->brevo_domain;
$this->client_brevo_endpoint = $this->email_object->settings->brevo_endpoint;
} else {
$this->email_object->settings->email_sending_method = 'default';

View File

@ -40,6 +40,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Mail;
use Log;
use Turbo124\Beacon\Facades\LightLogs;
class Email implements ShouldQueue
@ -62,10 +63,6 @@ class Email implements ShouldQueue
protected ?string $client_brevo_secret = null;
protected ?string $client_brevo_domain = null;
protected ?string $client_brevo_endpoint = null;
private string $mailer = 'default';
public Mailable $mailable;
@ -238,10 +235,13 @@ class Email implements ShouldQueue
public function email()
{
// $this->setMailDriver();
Log::info("mail(): " . $this->mailer);
Log::info($this->client_brevo_secret);
/* Init the mailer*/
$mailer = Mail::mailer($this->mailer);
/* Additional configuration if using a client third party mailer */
if ($this->client_postmark_secret) {
$mailer->postmark_config($this->client_postmark_secret);
@ -252,7 +252,7 @@ class Email implements ShouldQueue
}
if ($this->client_brevo_secret) {
$mailer->brevo_config($this->client_brevo_secret, $this->client_brevo_domain, $this->client_brevo_endpoint);
$mailer->brevo_config($this->client_brevo_secret);
}
/* Attempt the send! */
@ -385,7 +385,7 @@ class Email implements ShouldQueue
}
/* GMail users are uncapped */
if (in_array($this->email_object->settings->email_sending_method, ['gmail', 'office365', 'client_postmark', 'client_mailgun'])) {
if (in_array($this->email_object->settings->email_sending_method, ['gmail', 'office365', 'client_postmark', 'client_mailgun', 'client_brevo'])) {
return false;
}
@ -461,6 +461,8 @@ class Email implements ShouldQueue
*/
private function setMailDriver(): self
{
Log::info("E-Mail Sending Method (setMailDriver): " . $this->email_object->settings->email_sending_method);
Log::info(json_encode($this->email_object->settings));
switch ($this->email_object->settings->email_sending_method) {
case 'default':
$this->mailer = config('mail.default');
@ -541,10 +543,6 @@ class Email implements ShouldQueue
$this->client_brevo_secret = null;
$this->client_brevo_domain = null;
$this->client_brevo_endpoint = null;
//always dump the drivers to prevent reuse
app('mail.manager')->forgetMailers();
}
@ -615,10 +613,8 @@ class Email implements ShouldQueue
*/
private function setBrevoMailer()
{
if (strlen($this->email_object->settings->brevo_secret) > 2 && strlen($this->email_object->settings->brevo_domain) > 2) {
if (strlen($this->email_object->settings->brevo_secret) > 2) {
$this->client_brevo_secret = $this->email_object->settings->brevo_secret;
$this->client_brevo_domain = $this->email_object->settings->brevo_domain;
$this->client_brevo_endpoint = $this->email_object->settings->brevo_endpoint;
} else {
$this->email_object->settings->email_sending_method = 'default';

30
config/brevo.php Normal file
View File

@ -0,0 +1,30 @@
<?php
return [
/* @deprecated
|--------------------------------------------------------------------------
| Brevo credentials
|--------------------------------------------------------------------------
|
| Here you may provide your Postmark server API token.
|
*/
'secret' => env('BREVO_SECRET'),
/*
|--------------------------------------------------------------------------
| Guzzle options
|--------------------------------------------------------------------------
|
| Under the hood we use Guzzle to make API calls to Postmark.
| Here you may provide any request options for Guzzle.
|
*/
'guzzle' => [
'timeout' => 120,
'connect_timeout' => 120,
],
];

View File

@ -26,10 +26,7 @@ return [
],
'brevo' => [
'domain' => env('BREVO_DOMAIN', ''),
'secret' => env('BREVO_SECRET', ''),
'endpoint' => env('BREVO_ENDPOINT', 'api.mailgun.net'),
'scheme' => 'https',
'key' => env('BREVO_SECRET', ''),
],
'postmark' => [

File diff suppressed because it is too large Load Diff