SMTP emails working with EmailSender...haven't tested attaching things though
parent
b4dcbc9846
commit
2a145bfa3e
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Emails;
|
||||||
|
|
||||||
|
|
||||||
|
use BusinessLogic\Tickets\Attachment;
|
||||||
|
use BusinessLogic\Tickets\Ticket;
|
||||||
|
use PHPMailer;
|
||||||
|
|
||||||
|
class BasicEmailSender implements EmailSender {
|
||||||
|
|
||||||
|
function sendEmail($emailBuilder, $heskSettings, $modsForHeskSettings, $sendAsHtml) {
|
||||||
|
$mailer = new PHPMailer();
|
||||||
|
|
||||||
|
if ($heskSettings['smtp']) {
|
||||||
|
$mailer->isSMTP();
|
||||||
|
$mailer->SMTPAuth = true;
|
||||||
|
if ($heskSettings['smtp_ssl']) {
|
||||||
|
$mailer->SMTPSecure = "ssl";
|
||||||
|
} elseif ($heskSettings['smtp_tls']) {
|
||||||
|
$mailer->SMTPSecure = "tls";
|
||||||
|
}
|
||||||
|
$mailer->Host = $heskSettings['smtp_host_name'];
|
||||||
|
$mailer->Port = $heskSettings['smtp_host_port'];
|
||||||
|
$mailer->Username = $heskSettings['smtp_user'];
|
||||||
|
$mailer->Password = $heskSettings['smtp_password'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$mailer->FromName = $heskSettings['noreply_name'] ? $heskSettings['noreply_name'] : '';
|
||||||
|
$mailer->From = $heskSettings['noreply_mail'];
|
||||||
|
|
||||||
|
if ($emailBuilder->to !== null) {
|
||||||
|
foreach ($emailBuilder->to as $to) {
|
||||||
|
$mailer->addAddress($to);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($emailBuilder->cc !== null) {
|
||||||
|
foreach ($emailBuilder->cc as $cc) {
|
||||||
|
$mailer->addCC($cc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($emailBuilder->bcc !== null) {
|
||||||
|
foreach ($emailBuilder->bcc as $bcc) {
|
||||||
|
$mailer->addBCC($bcc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$mailer->Subject = $emailBuilder->subject;
|
||||||
|
|
||||||
|
if ($sendAsHtml) {
|
||||||
|
$mailer->Body = $emailBuilder->htmlMessage;
|
||||||
|
$mailer->AltBody = $emailBuilder->message;
|
||||||
|
} else {
|
||||||
|
$mailer->Body = $emailBuilder->message;
|
||||||
|
$mailer->isHTML(false);
|
||||||
|
}
|
||||||
|
$mailer->Timeout = $heskSettings['smtp_timeout'];
|
||||||
|
|
||||||
|
if ($mailer->send()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $mailer->ErrorInfo;
|
||||||
|
}
|
||||||
|
}
|
@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace BusinessLogic\Emails;
|
|
||||||
|
|
||||||
|
|
||||||
use BusinessLogic\Tickets\Attachment;
|
|
||||||
use BusinessLogic\Tickets\Ticket;
|
|
||||||
|
|
||||||
class PhpMailEmailSender implements EmailSender {
|
|
||||||
/**
|
|
||||||
* @param $emailBuilder EmailBuilder
|
|
||||||
* @param $heskSettings array
|
|
||||||
* @param $modsForHeskSettings array
|
|
||||||
*/
|
|
||||||
function sendEmail($emailBuilder, $heskSettings, $modsForHeskSettings) {
|
|
||||||
// TODO: Implement sendEmail() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $emailBuilder EmailBuilder
|
|
||||||
* @param $ticket Ticket
|
|
||||||
* @param $attachments Attachment[]
|
|
||||||
* @param $heskSettings array
|
|
||||||
* @param $modsForHeskSettings array
|
|
||||||
*/
|
|
||||||
function sendEmailWithTicket($emailBuilder, $ticket, $attachments, $heskSettings, $modsForHeskSettings) {
|
|
||||||
// TODO: Implement sendEmailWithTicket() method.
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace BusinessLogic\Emails;
|
|
||||||
|
|
||||||
|
|
||||||
use BusinessLogic\Tickets\Attachment;
|
|
||||||
use BusinessLogic\Tickets\Ticket;
|
|
||||||
|
|
||||||
class StmpEmailSender implements EmailSender {
|
|
||||||
/**
|
|
||||||
* @param $emailBuilder EmailBuilder
|
|
||||||
* @param $heskSettings array
|
|
||||||
* @param $modsForHeskSettings array
|
|
||||||
*/
|
|
||||||
function sendEmail($emailBuilder, $heskSettings, $modsForHeskSettings) {
|
|
||||||
// TODO: Implement sendEmail() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $emailBuilder EmailBuilder
|
|
||||||
* @param $ticket Ticket
|
|
||||||
* @param $attachments Attachment[]
|
|
||||||
* @param $heskSettings array
|
|
||||||
* @param $modsForHeskSettings array
|
|
||||||
*/
|
|
||||||
function sendEmailWithTicket($emailBuilder, $ticket, $attachments, $heskSettings, $modsForHeskSettings) {
|
|
||||||
// TODO: Implement sendEmailWithTicket() method.
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Emails;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class BasicEmailSenderIntegrationTest extends TestCase {
|
||||||
|
/**
|
||||||
|
* @var $emailSender BasicEmailSender;
|
||||||
|
*/
|
||||||
|
private $emailSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $heskSettings array
|
||||||
|
*/
|
||||||
|
private $heskSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var $modsForHeskSettings array
|
||||||
|
*/
|
||||||
|
private $modsForHeskSettings;
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
global $hesk_settings, $modsForHesk_settings;
|
||||||
|
|
||||||
|
if (!defined('IN_SCRIPT')) {
|
||||||
|
define('IN_SCRIPT', 1);
|
||||||
|
}
|
||||||
|
require(__DIR__ . '/../../../../hesk_settings.inc.php');
|
||||||
|
require(__DIR__ . '/../../integration_test_mfh_settings.php');
|
||||||
|
|
||||||
|
$this->emailSender = new BasicEmailSender();
|
||||||
|
$this->heskSettings = $hesk_settings;
|
||||||
|
$this->modsForHeskSettings = $modsForHesk_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItCanSendHtmlMail() {
|
||||||
|
//-- Arrange
|
||||||
|
//$hesk_settings['smtp'] = 0 //Uncomment this to use PHPMail
|
||||||
|
$emailBuilder = new EmailBuilder();
|
||||||
|
$emailBuilder->to = array('mfh1@mailinator.com');
|
||||||
|
$emailBuilder->cc = array('mfh2@mailinator.com');
|
||||||
|
$emailBuilder->bcc = array('mfh3@mailinator.com');
|
||||||
|
$emailBuilder->message = "Test PLAIN TEXT message";
|
||||||
|
$emailBuilder->htmlMessage = "Test <b>HTML</b> <i>message</i>";
|
||||||
|
$emailBuilder->subject = "BasicEmailSenderIntegrationTest";
|
||||||
|
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->emailSender->sendEmail($emailBuilder, $this->heskSettings, $this->modsForHeskSettings, true);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
if ($result !== true) {
|
||||||
|
$this->fail($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItCanSendPlaintextMail() {
|
||||||
|
//-- Arrange
|
||||||
|
//$hesk_settings['smtp'] = 0 //Uncomment this to use PHPMail
|
||||||
|
$emailBuilder = new EmailBuilder();
|
||||||
|
$emailBuilder->to = array('mfh1@mailinator.com');
|
||||||
|
$emailBuilder->cc = array('mfh2@mailinator.com');
|
||||||
|
$emailBuilder->bcc = array('mfh3@mailinator.com');
|
||||||
|
$emailBuilder->message = "Test PLAIN TEXT message";
|
||||||
|
$emailBuilder->subject = "BasicEmailSenderIntegrationTest";
|
||||||
|
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$result = $this->emailSender->sendEmail($emailBuilder, $this->heskSettings, $this->modsForHeskSettings, false);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
if ($result !== true) {
|
||||||
|
$this->fail($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
// Copy this file as "integration_test_mfh_settings.php" to use
|
||||||
|
//-- Integration test data for Mods for HESK settings
|
Loading…
Reference in New Issue