initial changings

This commit is contained in:
paulwer 2023-12-18 19:37:13 +01:00
parent 9dd6ead39e
commit 3206e46349
13 changed files with 1623 additions and 1380 deletions

View File

@ -13,5 +13,10 @@ namespace Illuminate\Contracts\Mail
{
return true;
}
public function brevo_config(string $key)
{
return true;
}
}
}

View File

@ -229,7 +229,7 @@ class CompanySettings extends BaseSettings
public $require_quote_signature = false; //@TODO ben to confirm
//email settings
public $email_sending_method = 'default'; //enum 'default','gmail','office365' 'client_postmark', 'client_mailgun' //@implemented
public $email_sending_method = 'default'; //enum 'default','gmail','office365' 'client_postmark', 'client_mailgun' , 'client_brevo' //@implemented
public $gmail_sending_user_id = '0'; //@implemented
@ -451,6 +451,12 @@ class CompanySettings extends BaseSettings
public $mailgun_endpoint = 'api.mailgun.net'; //api.eu.mailgun.net
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
@ -505,6 +511,7 @@ 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',
@ -521,6 +528,8 @@ class CompanySettings extends BaseSettings
'postmark_secret' => 'string',
'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' //@implemented
public string $email_sending_method = 'default'; // enum 'default', 'gmail', 'office365', 'client_postmark', 'client_mailgun' , 'brevo_mailgun' //@implemented
public string $gmail_sending_user_id = '0'; //@implemented
@ -433,6 +433,12 @@ class SettingsData
public string $mailgun_endpoint = 'api.mailgun.net'; // api.eu.mailgun.net
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

@ -62,6 +62,9 @@ class NinjaMailerJob implements ShouldQueue
protected $client_mailgun_domain = false;
protected $client_brevo_secret = false;
protected $client_brevo_domain = false;
public function __construct(NinjaMailerObject $nmo, bool $override = false)
{
@ -133,6 +136,10 @@ class NinjaMailerJob implements ShouldQueue
$mailer->mailgun_config($this->client_mailgun_secret, $this->client_mailgun_domain, $this->nmo->settings->mailgun_endpoint);
}
if ($this->client_brevo_secret) {
$mailer->brevo_config($this->client_brevo_secret, $this->client_brevo_domain, $this->nmo->settings->brevo_endpoint);
}
$mailer
->to($this->nmo->to_user->email)
->send($this->nmo->mailable);
@ -272,6 +279,10 @@ class NinjaMailerJob implements ShouldQueue
$this->mailer = 'mailgun';
$this->setMailgunMailer();
return $this;
case 'client_brevo':
$this->mailer = 'brevo';
$this->setBrevoMailer();
return $this;
default:
break;
@ -322,6 +333,10 @@ class NinjaMailerJob implements ShouldQueue
$this->client_mailgun_domain = false;
$this->client_brevo_secret = false;
$this->client_brevo_domain = false;
//always dump the drivers to prevent reuse
app('mail.manager')->forgetMailers();
}
@ -385,6 +400,30 @@ class NinjaMailerJob implements ShouldQueue
->from($sending_email, $sending_user);
}
/**
* Configures Brevo using client supplied secret
* as the Mailer
*/
private function setBrevoMailer()
{
if (strlen($this->nmo->settings->brevo_secret) > 2 && strlen($this->nmo->settings->brevo_domain) > 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();
}
$user = $this->resolveSendingUser();
$sending_email = (isset($this->nmo->settings->custom_sending_email) && stripos($this->nmo->settings->custom_sending_email, "@")) ? $this->nmo->settings->custom_sending_email : $user->email;
$sending_user = (isset($this->nmo->settings->email_from_name) && strlen($this->nmo->settings->email_from_name) > 2) ? $this->nmo->settings->email_from_name : $user->name();
$this->nmo
->mailable
->from($sending_email, $sending_user);
}
/**
* Configures Postmark using client supplied secret
* as the Mailer
@ -527,7 +566,7 @@ class NinjaMailerJob implements ShouldQueue
}
/* GMail users are uncapped */
if (Ninja::isHosted() && (in_array($this->nmo->settings->email_sending_method, ['gmail', 'office365', 'client_postmark', 'client_mailgun']))) {
if (Ninja::isHosted() && (in_array($this->nmo->settings->email_sending_method, ['gmail', 'office365', 'client_postmark', 'client_mailgun', 'client_brevo']))) {
return false;
}

View File

@ -100,7 +100,6 @@ class AppServiceProvider extends ServiceProvider
return $this;
});
Mailer::macro('mailgun_config', function (string $secret, string $domain, string $endpoint = 'api.mailgun.net') {
// @phpstan-ignore /** @phpstan-ignore-next-line **/
Mailer::setSymfonyTransport(app('mail.manager')->createSymfonyTransport([
@ -114,6 +113,19 @@ class AppServiceProvider extends ServiceProvider
return $this;
});
Mailer::macro('brevo_config', function (string $secret, string $domain, string $endpoint = 'api.mailgun.net') {
// @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'),
]));
return $this;
});
}
public function register(): void

View File

@ -55,6 +55,12 @@ class AdminEmail implements ShouldQueue
protected ?string $client_mailgun_endpoint = null;
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;
@ -133,6 +139,10 @@ class AdminEmail implements ShouldQueue
$mailer->mailgun_config($this->client_mailgun_secret, $this->client_mailgun_domain, $this->client_mailgun_endpoint);
}
if ($this->client_brevo_secret) {
$mailer->brevo_config($this->client_brevo_secret, $this->client_brevo_domain, $this->client_brevo_endpoint);
}
/* Attempt the send! */
try {
nlog("Using mailer => " . $this->mailer . " " . now()->toDateTimeString());
@ -333,6 +343,10 @@ class AdminEmail implements ShouldQueue
$this->mailer = 'mailgun';
$this->setMailgunMailer();
return $this;
case 'client_brevo':
$this->mailer = 'brevo';
$this->setBrevoMailer();
return $this;
default:
$this->mailer = config('mail.default');
@ -386,6 +400,12 @@ class AdminEmail implements ShouldQueue
$this->client_mailgun_endpoint = null;
$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();
}
@ -450,6 +470,30 @@ class AdminEmail implements ShouldQueue
$this->mailable
->from($sending_email, $sending_user);
}
/**
* Configures Brevo using client supplied secret
* as the Mailer
*/
private function setBrevoMailer()
{
if (strlen($this->email_object->settings->brevo_secret) > 2 && strlen($this->email_object->settings->brevo_domain) > 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';
return $this->setMailDriver();
}
$user = $this->resolveSendingUser();
$sending_email = (isset($this->email_object->settings->custom_sending_email) && stripos($this->email_object->settings->custom_sending_email, "@")) ? $this->email_object->settings->custom_sending_email : $user->email;
$sending_user = (isset($this->email_object->settings->email_from_name) && strlen($this->email_object->settings->email_from_name) > 2) ? $this->email_object->settings->email_from_name : $user->name();
$this->mailable
->from($sending_email, $sending_user);
}
/**
* Configures Postmark using client supplied secret

View File

@ -60,6 +60,12 @@ class Email implements ShouldQueue
protected ?string $client_mailgun_endpoint = null;
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;
@ -245,6 +251,10 @@ class Email implements ShouldQueue
$mailer->mailgun_config($this->client_mailgun_secret, $this->client_mailgun_domain, $this->client_mailgun_endpoint);
}
if ($this->client_brevo_secret) {
$mailer->brevo_config($this->client_brevo_secret, $this->client_brevo_domain, $this->client_brevo_endpoint);
}
/* Attempt the send! */
try {
nlog("Using mailer => " . $this->mailer . " " . now()->toDateTimeString());
@ -472,6 +482,10 @@ class Email implements ShouldQueue
$this->mailer = 'mailgun';
$this->setMailgunMailer();
return $this;
case 'client_brevo':
$this->mailer = 'brevo';
$this->setBrevoMailer();
return $this;
default:
$this->mailer = config('mail.default');
@ -525,6 +539,12 @@ class Email implements ShouldQueue
$this->client_mailgun_endpoint = null;
$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();
}
@ -589,6 +609,30 @@ class Email implements ShouldQueue
$this->mailable
->from($sending_email, $sending_user);
}
/**
* Configures Brevo using client supplied secret
* as the Mailer
*/
private function setBrevoMailer()
{
if (strlen($this->email_object->settings->brevo_secret) > 2 && strlen($this->email_object->settings->brevo_domain) > 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';
return $this->setMailDriver();
}
$user = $this->resolveSendingUser();
$sending_email = (isset($this->email_object->settings->custom_sending_email) && stripos($this->email_object->settings->custom_sending_email, "@")) ? $this->email_object->settings->custom_sending_email : $user->email;
$sending_user = (isset($this->email_object->settings->email_from_name) && strlen($this->email_object->settings->email_from_name) > 2) ? $this->email_object->settings->email_from_name : $user->name();
$this->mailable
->from($sending_email, $sending_user);
}
/**
* Configures Postmark using client supplied secret

View File

@ -91,6 +91,7 @@
"sprain/swiss-qr-bill": "^4.3",
"square/square": "30.0.0.*",
"stripe/stripe-php": "^12",
"symfony/brevo-mailer": "^7.0",
"symfony/http-client": "^6.0",
"symfony/mailgun-mailer": "^6.1",
"symfony/postmark-mailer": "^6.1",

73
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "28b57fe6eac3d71c607125cda9a6a537",
"content-hash": "ba57ee16621201bac10def4422ba9161",
"packages": [
{
"name": "afosto/yaac",
@ -10716,6 +10716,75 @@
},
"time": "2023-10-16T18:04:12+00:00"
},
{
"name": "symfony/brevo-mailer",
"version": "v7.0.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/brevo-mailer.git",
"reference": "83db87e0f44653cd40aeef54a2f57ab6bfccadfe"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/brevo-mailer/zipball/83db87e0f44653cd40aeef54a2f57ab6bfccadfe",
"reference": "83db87e0f44653cd40aeef54a2f57ab6bfccadfe",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/mailer": "^5.4.21|^6.2.7|^7.0"
},
"conflict": {
"symfony/mime": "<6.2"
},
"require-dev": {
"symfony/http-client": "^6.3|^7.0",
"symfony/webhook": "^6.3|^7.0"
},
"type": "symfony-mailer-bridge",
"autoload": {
"psr-4": {
"Symfony\\Component\\Mailer\\Bridge\\Brevo\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Pierre Tanguy",
"homepage": "https://github.com/petanguy"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Brevo Mailer Bridge",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/brevo-mailer/tree/v7.0.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-11-06T17:20:05+00:00"
},
{
"name": "symfony/console",
"version": "v6.4.1",
@ -18046,5 +18115,5 @@
"platform-dev": {
"php": "^8.1|^8.2"
},
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}

View File

@ -28,7 +28,7 @@ return [
| sending an e-mail. You will specify which one you are using for your
| mailers below. You are free to add additional mailers as required.
|
| Supported: "smtp", "sendmail", "mailgun", "ses",
| Supported: "smtp", "sendmail", "mailgun", "brevo", "ses",
| "postmark", "log", "array", "failover"
|
*/
@ -54,6 +54,10 @@ return [
'transport' => 'mailgun',
],
'brevo' => [
'transport' => 'brevo',
],
'postmark' => [
'transport' => 'postmark',
],

View File

@ -12,7 +12,7 @@ return [
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Mailgun, Postmark, AWS and more. This file provides the de facto
| as Mailgun, Brevo, Postmark, AWS and more. This file provides the de facto
| location for this type of information, allowing packages to have
| a conventional file to locate the various service credentials.
|
@ -25,6 +25,13 @@ return [
'scheme' => 'https',
],
'brevo' => [
'domain' => env('BREVO_DOMAIN', ''),
'secret' => env('BREVO_SECRET', ''),
'endpoint' => env('BREVO_ENDPOINT', 'api.mailgun.net'),
'scheme' => 'https',
],
'postmark' => [
'token' => env('POSTMARK_SECRET', ''),
],

View File

@ -2237,6 +2237,8 @@ $lang = array(
'encryption' => 'Encryption',
'mailgun_domain' => 'Mailgun Domain',
'mailgun_private_key' => 'Mailgun Private Key',
'brevo_domain' => 'Brevo Domain',
'brevo_private_key' => 'Brevo Private Key',
'send_test_email' => 'Send test email',
'select_label' => 'Select Label',
'label' => 'Label',
@ -4891,6 +4893,7 @@ $lang = array(
'email_alignment' => 'Email Alignment',
'pdf_preview_location' => 'PDF Preview Location',
'mailgun' => 'Mailgun',
'brevo' => 'Brevo',
'postmark' => 'Postmark',
'microsoft' => 'Microsoft',
'click_plus_to_create_record' => 'Click + to create a record',

File diff suppressed because it is too large Load Diff