diff --git a/application/Espo/Entities/Email.php b/application/Espo/Entities/Email.php index 85e5354390..65ca1dba60 100644 --- a/application/Espo/Entities/Email.php +++ b/application/Espo/Entities/Email.php @@ -717,6 +717,11 @@ class Email extends Entity return $this->getValueObject('sentBy'); } + public function setSentBy(Link|User|null $sentBy): self + { + return $this->setRelatedLinkOrEntity('sentBy', $sentBy); + } + public function getGroupFolder(): ?Link { /** @var ?Link */ diff --git a/application/Espo/Repositories/Email.php b/application/Espo/Repositories/Email.php index 5b141b6b33..b998274e10 100644 --- a/application/Espo/Repositories/Email.php +++ b/application/Espo/Repositories/Email.php @@ -333,6 +333,7 @@ class Email extends Database implements $this->addUserByEmailAddressId($entity, $ids[0], true); if (!$entity->getSentBy()) { + /** @var UserEntity $user */ $user = $this->getEmailAddressRepository() ->getEntityByAddressId( $entity->get('fromEmailAddressId'), @@ -340,7 +341,8 @@ class Email extends Database implements true ); - if ($user) { + if ($user && $entity->getStatus() !== EmailEntity::STATUS_DRAFT) { + $entity->setSentBy($user); $entity->set('sentById', $user->getId()); } }