public function testSend()
 {
     $message = new Swift_Message();
     $message->setFrom('*****@*****.**', 'Johnny #5');
     $message->setSubject('Is alive!');
     $message->addTo('*****@*****.**', 'A. Friend');
     $message->addTo('*****@*****.**');
     $message->addCc('*****@*****.**');
     $message->addCc('*****@*****.**', 'Extra 2');
     $message->addBcc('*****@*****.**');
     $message->addBcc('*****@*****.**', 'Extra 4');
     $message->addPart('<q>Help me Rhonda</q>', 'text/html');
     $message->addPart('Doo-wah-ditty.', 'text/plain');
     $attachment = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain');
     $attachment2 = Swift_Attachment::newInstance('This is the plain text attachment.', 'hello.txt', 'text/plain');
     $attachment2->setDisposition('inline');
     $message->attach($attachment);
     $message->attach($attachment2);
     $message->setPriority(1);
     $headers = $message->getHeaders();
     $headers->addTextHeader('X-PM-Tag', 'movie-quotes');
     $messageId = $headers->get('Message-ID')->getId();
     $transport = new PostmarkTransportStub('TESTING_SERVER');
     $client = $this->getMock('GuzzleHttp\\Client', array('request'));
     $transport->setHttpClient($client);
     $o = PHP_OS;
     $v = phpversion();
     $client->expects($this->once())->method('request')->with($this->equalTo('POST'), $this->equalTo('https://api.postmarkapp.com/email'), $this->equalTo(['headers' => ['X-Postmark-Server-Token' => 'TESTING_SERVER', 'User-Agent' => "swiftmailer-postmark (PHP Version: {$v}, OS: {$o})", 'Content-Type' => 'application/json'], 'json' => ['From' => '"Johnny #5" <*****@*****.**>', 'To' => '"A. Friend" <*****@*****.**>,you+two@example.com', 'Cc' => 'another+1@example.com,"Extra 2" <*****@*****.**>', 'Bcc' => 'another+3@example.com,"Extra 4" <*****@*****.**>', 'Subject' => 'Is alive!', 'Tag' => 'movie-quotes', 'TextBody' => 'Doo-wah-ditty.', 'HtmlBody' => '<q>Help me Rhonda</q>', 'Headers' => [['Name' => 'Message-ID', 'Value' => '<' . $messageId . '>'], ['Name' => 'X-PM-KeepID', 'Value' => 'true'], ['Name' => 'X-Priority', 'Value' => '1 (Highest)']], 'Attachments' => [['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt'], ['ContentType' => 'text/plain', 'Content' => 'VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCBhdHRhY2htZW50Lg==', 'Name' => 'hello.txt', 'ContentID' => 'cid:' . $attachment2->getId()]]]]));
     $transport->send($message);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function prepare($from, $fromName, array $to, $subject, $body, array $attachments = array(), array $options = array())
 {
     $this->mail = \Swift_Message::newInstance()->setSubject($subject)->setFrom($from)->setBody($body, 'text/html');
     foreach ($to as $receiver) {
         $this->mail->addTo($receiver);
     }
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             $this->mail->attach(\Swift_Attachment::fromPath($attachment));
         }
     }
 }
Esempio n. 3
0
 private function sendMessage(FollowUserEvent $event)
 {
     $templating = $this->containerAware->get('templating');
     $message = new \Swift_Message("Vous avez une nouvel abonné!", $templating->render('SnoozitSkuagBundle:Mail/Follow:UserFollowed.html.twig', array('followerUserName' => $event->getUser()->getUsername())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 private function sendGuestMessage(InterestEvent $event)
 {
     $templating = $this->containerAware->get('templating');
     $message = new \Swift_Message("Désistement sur votre annonce!", $templating->render('SnoozitSkuagBundle:Mail/Interest:UnInterestedMail.html.twig', array('slug' => $event->getAdvertSlug(), 'id' => $event->getAdvertId(), 'title' => $event->getAdvertTitle(), 'userInterested' => $event->getCustomerUsername(), 'ownername' => $event->getGuestOwnerName())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 private function sendMessage(InterestEvent $event)
 {
     $templating = $this->containerAware->get('templating');
     $message = new \Swift_Message("Vente réussie à modifier SoldSuccessListener", $templating->render('SnoozitSkuagBundle:Mail/Interest:InterestedMail.html.twig', array('slug' => $event->getAdvertSlug(), 'id' => $event->getAdvertId(), 'title' => $event->getAdvertTitle(), 'userInterested' => $event->getCustomerUsername(), 'ownername' => $event->getOwnerUsername())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 private function sendMessage(User $user)
 {
     $templating = $this->containerAware->get('templating');
     $message = new \Swift_Message("Snoozit vous souhaite la bienvenue!", $templating->render('SnoozitSkuagBundle:Mail/Registration:RegistrationMail.html.twig', array('user' => $user->getUsername())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 /**
  * @inheritDoc
  */
 public static function fromWrappedMessage(MailWrappedMessage $wrappedMessage = null, $transport = null)
 {
     if (!$wrappedMessage instanceof MailWrappedMessage) {
         throw new MailWrapperSetupException('Not MailWrappedMessage');
     }
     $message = new \Swift_Message();
     foreach ($wrappedMessage->getToRecipients() as $address) {
         $message->addTo($address);
     }
     foreach ($wrappedMessage->getCcRecipients() as $address) {
         $message->addCc($address);
     }
     foreach ($wrappedMessage->getBccRecipients() as $address) {
         $message->addBcc($address);
     }
     $message->setReplyTo($wrappedMessage->getReplyTo());
     $message->setFrom($wrappedMessage->getFrom());
     $message->setSubject($wrappedMessage->getSubject());
     if ($wrappedMessage->getContentText()) {
         $message->setBody($wrappedMessage->getContentText());
     }
     if ($wrappedMessage->getContentHtml()) {
         $message->setBody($wrappedMessage->getContentHtml(), 'text/html');
     }
     return $message;
 }
Esempio n. 8
0
 private function sendMessage(NegoceEvent $event)
 {
     $templating = $this->containerAware->get('templating');
     $message = new \Swift_Message("Vous avez reçu une offre!", $templating->render('SnoozitSkuagBundle:Mail/Negoce:NegoceMail.html.twig', array('slug' => $event->getAdvertSlug(), 'id' => $event->getAdvertId(), 'title' => $event->getAdvertTitle(), 'userInterested' => $event->getCustomerUsername(), 'ownername' => $event->getOwnerUsername(), 'price' => $event->getPrice())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 /**
  * @param \FTC\Bundle\AuthBundle\Entity\User $recipient
  * @param string $subject
  * @param string $body
  *
  * @return \Swift_Message
  */
 protected function createEmail($recipient, $subject, $body)
 {
     $email = new \Swift_Message();
     $email->addTo($recipient->getEmail(), $recipient->getFullname());
     $email->setFrom('*****@*****.**', 'FixThatCode.com');
     $email->setSubject($subject);
     $email->setBody($body, 'text/html');
     return $email;
 }
Esempio n. 10
0
 private function createMessage($body, $data, $config)
 {
     $message = new \Swift_Message();
     $message->setFrom($config['from']['email']);
     $message->setSubject($config['subject']);
     $message->setBody($body);
     $message->addTo($data->getEmail());
     //        $message->setSender($config['from']['name'])
     return $message;
 }
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$entity instanceof Application) {
         return;
     }
     $message = new \Swift_Message('Nouvelle candidature', 'Vous avez reçu une nouvelle candidature');
     $message->addTo($entity->getAuthor())->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$entity instanceof Application) {
         return;
     }
     $message = new \Swift_Message("Nouvelle candidature", "Vous avez reçu une nouvelle candidature !");
     $message->addTo("*****@*****.**")->addFrom("*****@*****.**");
     $this->mailer->send($message);
 }
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if (!$entity instanceof Application) {
         return;
     }
     $message = new \Swift_Message('Nouvelle candidature', 'Vous avez reçu une nouvelle candidature.');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     // On veut envoyer un email que pour les entités Application
     if (!$entity instanceof Application) {
         return;
     }
     $message = new \Swift_Message('Nouvelle candidature', 'Vous avez reçu une nouvelle candidature.');
     $message->addTo($entity->getAdvert()->getAuthor());
     $this->mailer->send($message);
 }
Esempio n. 15
0
 /**
  * This is just for the demo sending.
  */
 public function action_send()
 {
     $message = new Swift_Message();
     $message->addTo($this->request->post('to'));
     $message->addFrom($this->request->post('from'));
     $message->setSubject($this->request->post('subject'));
     $message->setBody($this->request->post('message'));
     $mq = new MailQueue();
     $mq->add($message);
     $this->redirect('mailqueue/demo');
 }
Esempio n. 16
0
function sendMail($mail, $subject, $text)
{
    $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
    $swift = \Swift_Mailer::newInstance($transport);
    $message = new \Swift_Message($subject);
    $message->setFrom(env('MAIL_FROM'));
    $message->setSender(env('MAIL_FROM'));
    $message->setReplyTo(env('MAIL_FROM'));
    $message->setBody($text, 'text/plain');
    $message->addTo($mail);
    $swift->send($message);
}
Esempio n. 17
0
 public function postPersist(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     //a completer avec les entites
     if ($entity instanceof Commentaire || $entity instanceof Message || $entity instanceof User) {
         $em = $args->getEntityManager();
         $rep1 = $em->getRepository('APPAdminBundle:Generalite');
         $general = $rep1->find(1);
         if ($entity instanceof User) {
             $sujet = 'nouvel utilisateur inscrit';
             $string = 'Vous avez un nouvel utilisateur signalé sur ' . $general->getNom() . '.  Venez le voir: <br /><br /><a href="http://' . $general->getDomaine() . '">voir</a>';
             $to = $general->getEmail();
         } else {
             if ($entity instanceof Commentaire) {
                 $sujet = 'nouveau commentaire reçu';
                 $string = 'Vous avez un nouveau commentaire reçu sur ' . $general->getNom() . '.  Venez le voir: <br /><br /><a href="http://' . $general->getDomaine() . '">voir</a>';
                 $to = $general->getEmail();
             } else {
                 if ($entity instanceof Message) {
                     if ($entity->getPseudo() == 'administration') {
                         return false;
                     }
                     $sujet = 'nouveau message reçu';
                     $string = 'Vous avez un nouveau message reçu sur ' . $general->getNom() . '.  Venez le voir: <br /><br /><a href="http://' . $general->getDomaine() . '">voir</a>';
                     $to = $general->getEmail();
                 }
             }
         }
         $contenu = '<!DOCTYPE html>' . '<html lang="fr">' . '<head>' . ' <meta charset="utf-8" />' . ' <style>' . '     body {' . '         background-color: #E5E5E5;' . '         padding: 50px;' . '         font-family: comic sans ms;' . '     }' . '     header {' . '         width: 500px;' . '         margin: 0 auto;' . '         background-color: #F00;' . '         padding: 4px 5px 8px;' . '         color: #FFF;' . '         background-image: linear-gradient(#FE0000, #BD0100);' . '     }' . '     h1 {' . '         font-size: 1.1em;' . '         line-height: 0.9em;' . '         font-variant: small-caps;' . '         margin: 0.67em 0px;' . '         color: #FFF;' . '         text-align: center;' . '     }' . '     div.element {' . '         width: 500px;' . '         margin: 0 auto;' . '         padding: 5px 5px 30px;' . '         border-left: 1px solid #CDCDCD;' . '         border-right: 1px solid #CDCDCD;' . '         border-bottom: 1px solid #CDCDCD;' . '         background-color: #EAEAEA;' . '         background-image: linear-gradient(#FDFDFD, #EAEAEA);' . '         border-radius: 0px 0px 10px 10px;' . '     }' . '     div.element div {' . '         background-color: #fff;' . '         padding: 25px 10px;' . '         color: #777;' . '     }' . '     p {' . '         letter-spacing: -1px;' . '     }' . '     a {' . '         font-variant: small-caps;' . '         text-decoration: none;' . '         padding: 6px 12px;' . '         border: 1px solid #CDCDCD;' . '         border-radius: 6px;' . '         margin-top: 15px;' . '         background-color: #F00;' . '         background-image: linear-gradient(#FE0000, #BD0100);' . '         color: #FFF;' . '         font-family: comic sans ms;' . '         font-weight: 750;' . '     }' . ' </style>' . '</head>' . '<body>' . ' <header><h1>' . $sujet . '</h1></header>' . ' <div class="element">' . '     <div><p>' . $string . '</p></div>' . ' </div>' . '</body>' . '</html>';
         $message = new \Swift_Message($sujet, $contenu);
         $message->addTo($to)->addFrom('no_reply@' . $general->getDomaine())->setContentType('text/html');
         $this->mailer->send($message);
     } else {
         return;
     }
 }
Esempio n. 18
0
 public function finishOrderViaTheForm(FormInterface $form)
 {
     $cart = $this->loadCart();
     /** @var OrderEntity $entity */
     $entity = $form->getData();
     $entity->cart = $cart;
     try {
         $this->entity_manager->persist($entity);
         $this->entity_manager->flush();
         $data = ['name' => $entity->name, 'email' => $entity->email, 'cart' => $entity->cart, 'note' => $entity->note];
         $message = new \Swift_Message('Objednávka z webu Symfony.cz');
         $message->addFrom('*****@*****.**');
         $message->addTo($entity->email);
         $message->setBody($this->twig->render('AppBundle:Cart:email.html.twig', $data), 'text/html');
         $this->swift_mailer->send($message, $failed);
         $message = new \Swift_Message('Nová objednávka z webu Symfony.cz');
         $message->addFrom('*****@*****.**');
         $message->addTo('*****@*****.**');
         $message->setBody($this->twig->render('AppBundle:Cart:emailAdmin.html.twig', $data), 'text/html');
         $this->swift_mailer->send($message, $failed);
         $this->storeCart([]);
         return self::STATUS_OK;
     } catch (\Exception $e) {
     }
     return self::STATUS_ERROR;
 }
Esempio n. 19
0
 /**
  * @param \Swift_Message $instance
  * @param  array  $from              From addresses. An array of (email-address => name)
  * @param  array  $to                To addresses. An array of (email-address => name)
  * @param  array  $cc                Cc addresses. An array of (email-address => name) [optional]
  * @param  array  $bcc               Bcc addresses. An array of (email-address => name) [optional]
  * @param  array  $replyTo           Reply to addresses. An array of (email-address => name) [optional]
  */
 protected function setupMessageHeaders($instance, $from, $to, $cc = [], $bcc = [], $replyTo = [])
 {
     // Add from addresses
     foreach ($from as $address => $name) {
         $instance->addFrom($address, $name);
     }
     // Add to addresses
     foreach ($to as $address => $name) {
         $instance->addTo($address, $name);
     }
     // Add cc addresses
     foreach ($cc as $address => $name) {
         $instance->addCc($address, $name);
     }
     // Add bcc addresses
     foreach ($bcc as $address => $name) {
         $instance->addBcc($address, $name);
     }
     // Add reply to addresses
     foreach ($replyTo as $address => $name) {
         $instance->addReplyTo($address, $name);
     }
 }
Esempio n. 20
0
 public function addTo(Email $email)
 {
     $this->message->addTo($email->email, $email->name);
     return $this;
 }
 /**
  * 
  * @param string $address
  * @return \Tracker\Service\Mailer
  */
 public function setTo($address)
 {
     $this->message->addTo($address);
     return $this;
 }
Esempio n. 22
0
 public function testMessage()
 {
     $transport = $this->createTransport();
     $message = new \Swift_Message('Test Subject', '<p>Foo bar</p>', 'text/html');
     $attachment = new \Swift_Attachment('FILE_CONTENTS', 'filename.txt', 'text/plain');
     $message->attach($attachment);
     $message->addTo('*****@*****.**', 'To Name')->addFrom('*****@*****.**', 'From Name')->addCc('*****@*****.**', 'CC 1 Name')->addCc('*****@*****.**', 'CC 2 Name')->addBcc('*****@*****.**', 'BCC 1 Name')->addBcc('*****@*****.**', 'BCC 2 Name')->addReplyTo('*****@*****.**', 'Reply To Name');
     $mandrillMessage = $transport->getMandrillMessage($message);
     $this->assertEquals('<p>Foo bar</p>', $mandrillMessage['html']);
     $this->assertNull($mandrillMessage['text'], 'HTML only email should not contain plaintext counterpart');
     $this->assertEquals('Test Subject', $mandrillMessage['subject']);
     $this->assertEquals('*****@*****.**', $mandrillMessage['from_email']);
     $this->assertEquals('From Name', $mandrillMessage['from_name']);
     $this->assertMandrillMessageContainsRecipient('*****@*****.**', 'To Name', 'to', $mandrillMessage);
     $this->assertMandrillMessageContainsRecipient('*****@*****.**', 'CC 1 Name', 'cc', $mandrillMessage);
     $this->assertMandrillMessageContainsRecipient('*****@*****.**', 'CC 2 Name', 'cc', $mandrillMessage);
     $this->assertMandrillMessageContainsRecipient('*****@*****.**', 'BCC 1 Name', 'bcc', $mandrillMessage);
     $this->assertMandrillMessageContainsRecipient('*****@*****.**', 'BCC 2 Name', 'bcc', $mandrillMessage);
     $this->assertMandrillMessageContainsAttachment('text/plain', 'filename.txt', 'FILE_CONTENTS', $mandrillMessage);
     $this->assertArrayHasKey('Reply-To', $mandrillMessage['headers']);
     $this->assertEquals('reply-to@example.com <Reply To Name>', $mandrillMessage['headers']['Reply-To']);
     $this->assertMessageSendable($message);
 }
 public function advertNotification(Advert $entity)
 {
     $message = new \Swift_Message("Votre annonce sera bientôt en ligne!", $this->getTemplating()->render('SnoozitPlatformBundle:Mail/DoctrineListener/Persist:AdvertMail.html.twig', array('slug' => $entity->getSlug(), 'id' => $entity->getId(), 'title' => $entity->getTitle(), 'ownername' => $this->getUsername($entity))), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
Esempio n. 24
0
 /**
  * {@inheritdoc}
  *
  * @return $this|self
  */
 public function addTo($address, $name = null) : self
 {
     $this->message->addTo($address, $name);
     return $this;
 }
 /**
  * @param \Hyper\AdsBundle\Entity\Advertisement $entity
  * @return \Swift_Message
  */
 private function prepareMessage(Advertisement $entity)
 {
     $message = new \Swift_Message();
     $messageContent = $this->templating->render('HyperAdsBundle:Mailing:postPersistAnnouncement.html.twig', array('announcement' => $entity));
     $message->setBody($messageContent, 'text/html', 'utf-8');
     $message->setFrom($this->mailerFromEmail, $this->mailerFromName);
     $message->setSubject($this->translator->trans('announcement.edited', array('%user%' => $entity->getAdvertiser()->getUsernameCanonical(), '%title%' => $entity->getTitle()), 'HyperAdsBundle'));
     foreach ($this->mailingPersonList as $person) {
         $message->addTo($person);
     }
     return $message;
 }
Esempio n. 26
0
File: Email.php Progetto: hung5s/yap
 /**
  * Add email addresses
  *
  * @param Swift_Message $mail
  * @param string $addresses
  * @param string $field Address field, can be 'to','cc','bcc'
  */
 public function addMailAddresses(&$mail, $addresses, $field = 'to')
 {
     if (trim($addresses) == '') {
         return;
     }
     $addrs = explode(';', $addresses);
     foreach ($addrs as $addr) {
         //Reformat standar email "name" <email> to name,email
         $addr = str_replace('" <', '"<', $addr);
         $addr = str_replace('"<', ',', $addr);
         $addr = str_replace('"', '', $addr);
         $addr = str_replace('>', '', $addr);
         //Fix address format: name,email
         if (strpos($addr, ',') === false) {
             $addr = ',' . $addr;
         }
         $tmp = explode(',', $addr);
         switch ($field) {
             case 'cc':
                 $mail->addCc($tmp[1], $tmp[0]);
                 break;
             case 'bcc':
                 $mail->addBcc($tmp[1], $tmp[0]);
                 break;
             default:
                 $mail->addTo($tmp[1], $tmp[0]);
                 break;
         }
     }
 }
 public function advertNegoceNotification(AdvertNegoce $entity)
 {
     $message = new \Swift_Message("Une proposition vient d'arriver", $this->getTemplating()->render('SnoozitPlatformBundle:Mail/DoctrineListener/Persist:NegoceMail.html.twig', array('slug' => $entity->getAdvert()->getSlug(), 'id' => $entity->getAdvert()->getId(), 'title' => $entity->getAdvert()->getTitle(), 'userInterested' => $this->getUsername(), 'ownername' => $entity->getUser()->getUsername())), 'text/html');
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**');
     $this->mailer->send($message);
 }
 /**
  * @return \Swift_Message
  */
 public static function getValid()
 {
     $message = new \Swift_Message();
     $message->setFrom(MailWrapperTestBootstrap::$from);
     $message->addTo(MailWrapperTestBootstrap::$toAddresses[0]);
     $message->addTo(MailWrapperTestBootstrap::$toAddresses[1]);
     $message->addCC(MailWrapperTestBootstrap::$ccAddresses[0]);
     $message->addCC(MailWrapperTestBootstrap::$ccAddresses[1]);
     $message->addBCC(MailWrapperTestBootstrap::$bccAddresses[0]);
     $message->addBCC(MailWrapperTestBootstrap::$bccAddresses[1]);
     $message->addReplyTo(MailWrapperTestBootstrap::$alternate);
     $message->setSubject(MailWrapperTestBootstrap::$subject);
     $message->setBody(MailWrapperTestBootstrap::$contentText);
     $message->addPart(MailWrapperTestBootstrap::$contentHtml, 'text/html');
     return $message;
 }