diff --git a/Provider/Mail/DoctrineMailProvider.php b/Provider/Mail/DoctrineMailProvider.php index 56d73c2..2291283 100644 --- a/Provider/Mail/DoctrineMailProvider.php +++ b/Provider/Mail/DoctrineMailProvider.php @@ -5,6 +5,7 @@ use Doctrine\ORM\EntityManagerInterface; use Extellient\MailBundle\Entity\Mail; use Extellient\MailBundle\Entity\MailInterface; +use Extellient\MailBundle\Exception\MailerSenderEmptyException; /** * Class MailProviderDoctrine. @@ -38,7 +39,12 @@ public function save($mails) } //Persist all mails + /** @var MailInterface $mail */ foreach ($mails as $mail) { + if (empty($mail->getSenderEmail())) { + throw new MailerSenderEmptyException($mail); + } + $this->entityManager->persist($mail); } diff --git a/Services/MailBuilder.php b/Services/MailBuilder.php index 1aa1150..e73c89d 100644 --- a/Services/MailBuilder.php +++ b/Services/MailBuilder.php @@ -4,7 +4,6 @@ namespace Extellient\MailBundle\Services; use Extellient\MailBundle\Entity\Mail; -use Extellient\MailBundle\Exception\MailerSenderEmptyException; /** * Class MailBuilder @@ -47,10 +46,6 @@ public function createEmail($subject, $body, $recipients, $attachements = []) $mail = new Mail($subject, $body, $recipients); - if (empty($this->mailAddressFrom)) { - throw new MailerSenderEmptyException($mail); - } - $mail->setSenderEmail($this->mailAddressFrom); if (!empty($this->mailAliasFrom)) { diff --git a/Services/Mailer.php b/Services/Mailer.php index 2f8526c..f5e2f21 100644 --- a/Services/Mailer.php +++ b/Services/Mailer.php @@ -3,6 +3,7 @@ namespace Extellient\MailBundle\Services; use Extellient\MailBundle\Entity\Mail; +use Extellient\MailBundle\Entity\MailInterface; use Extellient\MailBundle\Provider\Mail\MailProviderInterface; /** @@ -47,9 +48,9 @@ public function createEmail($subject, $body, $recipients, $attachements = []) } /** - * Flush the Mail. + * Save mails. * - * @param $mails + * @param MailInterface|MailInterface[] $mails */ public function save($mails) {