diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php index c5289b3ffb..67835b0f09 100644 --- a/application/Espo/Services/Email.php +++ b/application/Espo/Services/Email.php @@ -813,24 +813,41 @@ class Email extends Record } } - return array( + return [ 'ids' => $ids, 'names' => $names - ); + ]; } public function sendTestEmail($data) { + $smtpParams = $data; + + $userId = $data['userId'] ?? null; + $fromAddress = $data['fromAddress'] ?? null; + + if ($userId) { + if ($userId !== $this->getUser()->id && !$this->getUser()->isAdmin()) { + throw new Forbidden(); + } + } + $email = $this->getEntityManager()->getEntity('Email'); $email->set([ 'subject' => 'EspoCRM: Test Email', 'isHtml' => false, - 'to' => $data['emailAddress'] + 'to' => $data['emailAddress'], ]); + if ($userId) { + if ($fromAddress) { + $this->applySmtpHandler($userId, $fromAddress, $smtpParams); + } + } + $emailSender = $this->getMailSender(); - $emailSender->useSmtp($data)->send($email); + $emailSender->useSmtp($smtpParams)->send($email); return true; } diff --git a/client/src/views/email-account/fields/test-send.js b/client/src/views/email-account/fields/test-send.js index b3eb48e7fb..00c26e1186 100644 --- a/client/src/views/email-account/fields/test-send.js +++ b/client/src/views/email-account/fields/test-send.js @@ -58,7 +58,8 @@ Espo.define('views/email-account/fields/test-send', 'views/outbound-email/fields 'fromName': this.getUser().get('name'), 'fromAddress': this.model.get('emailAddress'), 'type': 'emailAccount', - 'id': this.model.id + 'id': this.model.id, + 'userId': this.model.get('assignedUserId'), }; return data; }