EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
invitation custom email address
Yuri Kuznetsov56264e10c938
diff --git a/application/Espo/Modules/Crm/Business/Event/Invitations.php b/application/Espo/Modules/Crm/Business/Event/Invitations.phpindex bcced8a031..cddbfc4aef 100644--- a/application/Espo/Modules/Crm/Business/Event/Invitations.php+++ b/application/Espo/Modules/Crm/Business/Event/Invitations.php@@ -55,6 +55,10 @@ use Espo\Core\Utils\TemplateFileManager;use DateTime;+/**+ * Do not use. Use `Espo\Modules\Crm\Tools\Meeting\Invitation\Sender`.+ * @internal+ */class Invitations{private const TYPE_INVITATION = 'invitation';@@ -76,17 +80,17 @@ class Invitations/*** @throws SendingError*/- public function sendInvitation(Entity $entity, Entity $invitee, string $link): void+ public function sendInvitation(Entity $entity, Entity $invitee, string $link, ?string $emailAddress = null): void{- $this->sendInternal($entity, $invitee, $link);+ $this->sendInternal($entity, $invitee, $link, self::TYPE_INVITATION, $emailAddress);}/*** @throws SendingError*/- public function sendCancellation(Entity $entity, Entity $invitee, string $link): void+ public function sendCancellation(Entity $entity, Entity $invitee, string $link, ?string $emailAddress = null): void{- $this->sendInternal($entity, $invitee, $link, self::TYPE_CANCELLATION);+ $this->sendInternal($entity, $invitee, $link, self::TYPE_CANCELLATION, $emailAddress);}/**@@ -96,13 +100,14 @@ class InvitationsEntity $entity,Entity $invitee,string $link,- string $type = self::TYPE_INVITATION+ string $type,+ ?string $emailAddress,): void {$uid = $type === self::TYPE_INVITATION ? $this->createUniqueId($entity, $invitee, $link) : null;/** @var ?string $emailAddress */- $emailAddress = $invitee->get('emailAddress');+ $emailAddress ??= $invitee->get(Field::EMAIL_ADDRESS);if (!$emailAddress) {return;diff --git a/application/Espo/Modules/Crm/Tools/Meeting/Invitation/Invitee.php b/application/Espo/Modules/Crm/Tools/Meeting/Invitation/Invitee.phpindex 1e2b7b1eb9..4b2161ef24 100644--- a/application/Espo/Modules/Crm/Tools/Meeting/Invitation/Invitee.php+++ b/application/Espo/Modules/Crm/Tools/Meeting/Invitation/Invitee.php@@ -29,11 +29,12 @@namespace Espo\Modules\Crm\Tools\Meeting\Invitation;-class Invitee+readonly class Invitee{public function __construct(private string $entityType,- private string $id+ private string $id,+ private ?string $emailAddress = null,) {}public function getEntityType(): string@@ -45,4 +46,9 @@ class Invitee{return $this->id;}++ public function getEmailAddress(): ?string+ {+ return $this->emailAddress;+ }}diff --git a/application/Espo/Modules/Crm/Tools/Meeting/Invitation/Sender.php b/application/Espo/Modules/Crm/Tools/Meeting/Invitation/Sender.phpindex a05bc6e1aa..02865fbda0 100644--- a/application/Espo/Modules/Crm/Tools/Meeting/Invitation/Sender.php+++ b/application/Espo/Modules/Crm/Tools/Meeting/Invitation/Sender.php@@ -118,22 +118,30 @@ class Sender$collection = $builder->find();foreach ($collection as $attendee) {- if ($targets && !self::isInTargets($attendee, $targets)) {- continue;- }-$emailAddress = $attendee->get(Field::EMAIL_ADDRESS);+ if ($targets) {+ $target = self::findTarget($attendee, $targets);++ if (!$target) {+ continue;+ }++ if ($target->getEmailAddress()) {+ $emailAddress = $target->getEmailAddress();+ }+ }+if (!$emailAddress || in_array($emailAddress, $sentAddressList)) {continue;}if ($type === self::TYPE_INVITATION) {- $sender->sendInvitation($entity, $attendee, $link);+ $sender->sendInvitation($entity, $attendee, $link, $emailAddress);}if ($type === self::TYPE_CANCELLATION) {- $sender->sendCancellation($entity, $attendee, $link);+ $sender->sendCancellation($entity, $attendee, $link, $emailAddress);}$sentAddressList[] = $emailAddress;@@ -151,18 +159,18 @@ class Sender/*** @param Invitee[] $targets*/- private static function isInTargets(Entity $entity, array $targets): bool+ private static function findTarget(Entity $entity, array $targets): ?Invitee{foreach ($targets as $target) {if ($entity->getEntityType() === $target->getEntityType() &&$entity->getId() === $target->getId()) {- return true;+ return $target;}}- return false;+ return null;}private function getSender(): Invitations