Browse Source

Ajout d'un parametre 'service envoi email' pour changer depuis l'admin de mailjet à alwaysdata

develop
Fabien Normand 2 weeks ago
parent
commit
de3638862d
2 changed files with 30 additions and 10 deletions
  1. +18
    -1
      Definition/SiteSettingDefinition.php
  2. +12
    -9
      Notification/MailMailjetNotification.php

+ 18
- 1
Definition/SiteSettingDefinition.php View File

@@ -15,6 +15,12 @@ class SiteSettingDefinition extends AbstractSettingDefinition implements SiteSet
const SETTING_EMAIL_FROM = 'emailFrom';
const SETTING_EMAIL_FROM_NAME = 'emailFromName';


const SETTING_MAILER_HOST = 'mailerHost';
const SETTING_MAILER_HOST_MAILJET = 'mailjet';
const SETTING_MAILER_HOST_SMTP = 'smtp';


public function __construct()
{
// général
@@ -35,6 +41,17 @@ class SiteSettingDefinition extends AbstractSettingDefinition implements SiteSet
'name' => self::SETTING_MAINTENANCE_IP_AUTHORIZED,
]
);

$this->addSettingSelect(
[
'category' => self::CATEGORY_GENERAL,
'name' => self::SETTING_MAILER_HOST,
'choices' => [
'Mailjet' => self::SETTING_MAILER_HOST_MAILJET,
'SMTP (par défaut alwaysdata)' => self::SETTING_MAILER_HOST_SMTP,
]
]
);
}

public function getCategories(): array
@@ -44,4 +61,4 @@ class SiteSettingDefinition extends AbstractSettingDefinition implements SiteSet
];
}

}
}

+ 12
- 9
Notification/MailMailjetNotification.php View File

@@ -120,14 +120,17 @@ class MailMailjetNotification
);
}

// Classique (SMTP)
/*$transport = (new \Swift_SmtpTransport('smtp-placedulocal.alwaysdata.net', 587, 'tls'))
->setUsername('contact@placedulocal.fr')
->setPassword('7sgd5x2BVStJ69');
$mailer = new \Swift_Mailer($transport);
return $mailer->send($message);*/

// Mailjet
return $this->transport->send($message);
if($this->settingSolver->getSettingValue($siteDefault, SiteSettingDefinition::SETTING_MAILER_HOST)=== SiteSettingDefinition::SETTING_MAILER_HOST_SMTP){
$transport = (new \Swift_SmtpTransport(
$this->parameterBag->get('app.mail.host'),
$this->parameterBag->get('app.mail.port'),
$this->parameterBag->get('app.mail.ssl')))
->setUsername($this->parameterBag->get('app.mail.login'))
->setPassword($this->parameterBag->get('app.mail.password'));
$mailer = new \Swift_Mailer($transport);
return $mailer->send($message);
}else{
return $this->transport->send($message);
}
}
}

Loading…
Cancel
Save