Пример #1
0
 protected function send()
 {
     try {
         $message = new Message();
         $para = array_filter(explode(";", str_replace(array(" ", ","), array("", ";"), $this->dados["para"])));
         $message->addTo($para)->addFrom($this->dados["de"]["email"], $this->dados["de"]["nome"])->setSubject($this->dados["assunto"])->addReplyTo($this->dados["replay"]);
         $transport = new SmtpTransport();
         $options = new SmtpOptions(array('host' => 'mail.pessoaweb.com.br', 'connection_class' => 'login', 'connection_config' => array('username' => '*****@*****.**', 'password' => 'd1i2s3p4atch'), 'port' => 587));
         $html = new MimePart($this->dados["body"]);
         $html->type = "text/html";
         $html->charset = "UTF-8";
         $body = new MimeMessage();
         if (isset($this->dados["attachment"])) {
             foreach ($this->dados["attachment"] as $valor) {
                 $attachment = new MimePart($valor["arquivo"]);
                 $attachment->filename = $valor["titulo"];
                 if (isset($valor["tipo"])) {
                     $attachment->type = $valor["tipo"];
                 }
                 $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
                 $attachment->encoding = Mime::ENCODING_BASE64;
                 $body->setParts(array($attachment));
             }
         }
         $body->addPart($html);
         $message->setBody($body);
         $transport->setOptions($options);
         $transport->send($message);
         return $transport;
     } catch (\Exception $e) {
         debug(array("email" => $e->getMessage()), true);
     }
 }
Пример #2
0
 public function sendMessage(Message $message, Smtp $smtp, $recipient)
 {
     $message->addTo($recipient);
     if (!$this->config['disable_delivery']) {
         $smtp->send($message);
     }
 }
Пример #3
0
 private function sendEmail(array $listaEmailTo, array $listaEmailCC, $subject, $msg)
 {
     $renderer = $this->getServiceLocator()->get('ViewRenderer');
     $content = $renderer->render('email/template', array('msg' => nl2br($msg)));
     // make a header as html(template)
     $html = new MimePart($content);
     $html->type = "text/html";
     // make a image inline
     $image = new MimePart(fopen(__DIR__ . '\\..\\..\\..\\..\\Frota\\view\\email\\fundo_email_checkin.png', 'r'));
     $image->type = "image/jpeg";
     $image->id = "fundo_mail";
     $image->disposition = "inline";
     // build an email with a text(html) + image(inline)
     $body = new MimeMessage();
     $body->setParts(array($html, $image));
     // instance mail
     $mail = new Mail\Message();
     $mail->setBody($body);
     // will generate our code html from template.phtml
     $mail->setFrom($this->from['email'], utf8_decode($this->from['nome']));
     $mail->addTo($listaEmailTo);
     //$mail->addCc($listaEmailCC);
     $mail->setSubject(utf8_decode($subject));
     $transport = new Mail\Transport\Smtp($this->options);
     try {
         $transport->send($mail);
     } catch (RuntimeException $exc) {
         $this->logger->info('Erro ao enviar email para: ' . implode(',', $listaEmailTo) . ' erro: ' . $exc->getMessage() . "\n" . $exc->getTraceAsString());
         if ($exc->getMessage() == 'Could not open socket') {
             throw new Exception('O serviço de e-mail do MPM está indisponível no momento, a mensagem não foi enviada!');
         }
         throw new Exception("Não foi possível enviar a mensagem, ocorreu o seguinte erro: {$exc->getMessage()}!");
     }
 }
Пример #4
0
 public function getTransport()
 {
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('name' => 'bitweb.ee', 'host' => 'smtp.gmail.com', 'port' => '25', 'connection_class' => 'login', 'connection_config' => array('ssl' => 'tls', 'username' => '*****@*****.**', 'password' => 'erkinool123')));
     $transport->setOptions($options);
     return $transport;
 }
Пример #5
0
 public static function getMailerObject()
 {
     $response = array();
     $response['mail'] = new Message();
     $response['mail']->setEncoding(APP_CHARSET);
     if (strcasecmp(Config::get('concrete.mail.method'), 'smtp') == 0) {
         $config = array('host' => Config::get('concrete.mail.methods.smtp.server'));
         $username = Config::get('concrete.mail.methods.smtp.username');
         $password = Config::get('concrete.mail.methods.smtp.password');
         if ($username != '') {
             $config['connection_class'] = 'login';
             $config['connection_config'] = array();
             $config['connection_config']['username'] = $username;
             $config['connection_config']['password'] = $password;
         }
         $port = Config::get('concrete.mail.methods.smtp.port', '');
         if ($port != '') {
             $config['port'] = $port;
         }
         $encr = Config::get('concrete.mail.methods.smtp.encryption', '');
         if ($encr != '') {
             $config['connection_config']['ssl'] = $encr;
         }
         $transport = new SmtpTransport();
         $options = new SmtpOptions($config);
         $transport->setOptions($options);
         $response['transport'] = $transport;
     } else {
         $response['transport'] = new SendmailTransport();
     }
     return $response;
 }
Пример #6
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $sm Service manager
  *
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $sm)
 {
     // Load configurations:
     $config = $sm->get('VuFind\\Config')->get('config');
     // Create mail transport:
     $settings = ['host' => $config->Mail->host, 'port' => $config->Mail->port];
     if (isset($config->Mail->username) && isset($config->Mail->password)) {
         $settings['connection_class'] = 'login';
         $settings['connection_config'] = ['username' => $config->Mail->username, 'password' => $config->Mail->password];
         if (isset($config->Mail->secure)) {
             // always set user defined secure connection
             $settings['connection_config']['ssl'] = $config->Mail->secure;
         } else {
             // set default secure connection based on configured port
             if ($settings['port'] == '587') {
                 $settings['connection_config']['ssl'] = 'tls';
             } elseif ($settings['port'] == '487') {
                 $settings['connection_config']['ssl'] = 'ssl';
             }
         }
     }
     $transport = new Smtp();
     $transport->setOptions(new SmtpOptions($settings));
     // Create service:
     return new \VuFind\Mailer\Mailer($transport);
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     $transport = new Smtp();
     $transport->setOptions(new SmtpOptions($config['mail']['transport']['options']));
     return $transport;
 }
Пример #8
0
 public function getTransport()
 {
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('name' => 'localhost.localdomain', 'host' => $this->smtpHost, 'connection_class' => 'login', 'connection_config' => array('username' => $this->smtpUser, 'password' => $this->smtpPass)));
     $transport->setOptions($options);
     return $transport;
 }
Пример #9
0
 public function send($subject, $text, $to, $from = null)
 {
     if (!config('mail.enabled')) {
         return;
     }
     $message = new Message();
     $message->setSubject($subject);
     if ($from) {
         if (is_array($from)) {
             $message->setFrom($from[0], $from[1]);
         } else {
             $message->setFrom($from);
         }
     }
     $message->addTo($to);
     $content = '<html><head><title>' . $subject . '</title></head><body>' . $text . '</body></html>';
     $html = new Mime\Part($content);
     $html->setType(Mime\Mime::TYPE_HTML);
     $html->setCharset('utf-8');
     $mimeMessage = new Mime\Message();
     $mimeMessage->addPart($html);
     foreach ($this->attachments as $attachment) {
         $mimeMessage->addPart($attachment);
     }
     $message->setBody($mimeMessage);
     try {
         $transport = new SmtpTransport(new SmtpOptions(config('mail.options')));
         $transport->send($message);
     } catch (\Exception $e) {
         throw $e;
     }
     return $this;
 }
Пример #10
0
 /**
  * Sends a mail with the given data from the AppMailAccount
  * @param string $to
  * @param string $subject
  * @param string $content
  */
 public function sendMail(string $to, string $subject, string $content, array $files = [])
 {
     $content .= "\n\nThis is an automated mail. Please don't respond.";
     $text = new Mime\Part($content);
     $text->type = 'text/plain';
     $text->charset = 'utf-8';
     $text->disposition = Mime\Mime::DISPOSITION_INLINE;
     $parts[] = $text;
     foreach ($files as $filePath) {
         $fileContent = file_get_contents($filePath);
         $attachment = new Mime\Part($fileContent);
         $attachment->type = 'image/' . pathinfo($filePath, PATHINFO_EXTENSION);
         $attachment->filename = basename($filePath);
         $attachment->disposition = Mime\Mime::DISPOSITION_ATTACHMENT;
         $attachment->encoding = Mime\Mime::ENCODING_BASE64;
         $parts[] = $attachment;
     }
     $mime = new Mime\Message();
     $mime->setParts($parts);
     $appMailData = $this->getAppMailData();
     $message = new Message();
     $message->addTo($to)->addFrom($appMailData->getAdress())->setSubject($subject)->setBody($mime)->setEncoding('utf-8');
     $transport = new SmtpTransport();
     $options = new SmtpOptions(['name' => $appMailData->getHost(), 'host' => $appMailData->getHost(), 'connection_class' => 'login', 'connection_config' => ['username' => $appMailData->getLogin(), 'password' => $appMailData->getPassword()]]);
     $transport->setOptions($options);
     $transport->send($message);
 }
Пример #11
0
 public function run()
 {
     $transport = new SmtpTransport(new SmtpOptions(array('name' => $this->host, 'host' => $this->host, 'port' => $this->port, 'connection_config' => array('username' => $this->sender->getUsername(), 'password' => $this->sender->getPassword()))));
     if ($this->auth !== null) {
         $transport->getOptions()->setConnectionClass($this->auth);
     }
     $message = new Message();
     $message->addFrom($this->sender->getUsername())->setSubject($this->subject);
     if ($this->bcc) {
         $message->addBcc($this->recipients);
     } else {
         $message->addTo($this->recipients);
     }
     $body = new MimeMessage();
     if ($this->htmlBody == null) {
         $text = new MimePart($this->textBody);
         $text->type = "text/plain";
         $body->setParts(array($text));
     } else {
         $html = new MimePart($this->htmlBody);
         $html->type = "text/html";
         $body->setParts(array($html));
     }
     $message->setBody($body);
     $transport->send($message);
 }
Пример #12
0
 /**
  * Prepares the \Zend\Mail module
  */
 public function __construct()
 {
     $beehubConfig = \BeeHub::config();
     $config = $beehubConfig['email'];
     if (!empty($config['host'])) {
         // Configure the transporter for sending through SMTP
         $transport = new Mail\Transport\Smtp();
         $emailConfig = array('host' => $config['host']);
         if (!empty($config['port'])) {
             $emailConfig['port'] = $config['port'];
         }
         if (!empty($config['security'])) {
             $emailConfig['connection_config'] = array();
             $emailConfig['connection_config']['ssl'] = $config['security'];
         }
         if (!empty($config['auth_method'])) {
             $emailConfig['connection_class'] = $config['auth_method'];
             if (!isset($emailConfig['connection_config'])) {
                 $emailConfig['connection_config'] = array();
             }
             $emailConfig['connection_config']['username'] = $config['username'];
             $emailConfig['connection_config']['password'] = $config['password'];
         }
         $options = new Mail\Transport\SmtpOptions($emailConfig);
         $transport->setOptions($options);
     } else {
         // Else we use the Sendmail transporter (which actually just uses mail()
         $transport = new Mail\Transport\Sendmail();
     }
     $this->emailer = $transport;
 }
Пример #13
0
 /**
  * W momencie zapisu lokalizacji do bazy – wysyła się e-mail na stały adres administratora
  * serwisu z powiadomieniem o dodaniu nowej lokalizacji (nazwa miejsca + link do strony na froncie serwisu)
  *
  * @param Entity\Location $location
  */
 public function sendNotificationMail(Entity\Location $location)
 {
     /**
      * dane do wysylanego maila z potwierdzeniem, zdefiniowane w module.config.php
      */
     $config = $this->getServiceManager()->get('Config')['configuration']['location_mail_notification'];
     /* blokada wysylania maila (do testow) */
     if (false === $config['send_notification_mail']) {
         return false;
     }
     $uri = $this->getServiceManager()->get('request')->getUri();
     /* @var $uri \Zend\Uri\Http */
     $route = $this->getServiceManager()->get('router')->getRoute('location-details');
     /* @var $route \Zend\Mvc\Router\Http\Segment */
     /**
      * link do nowej lokalizacji
      */
     $base = sprintf('%s://%s', $uri->getScheme(), $uri->getHost());
     $url = $route->assemble(array('id' => $location->getId()));
     $mailConfig = (object) $config['message_config'];
     $html = strtr($mailConfig->message, array('%name%' => $location->getName(), '%link%' => $base . $url));
     $message = new Mime\Message();
     $message->setParts(array((new Mime\Part($html))->setType('text/html')));
     $mail = new Mail\Message();
     $mail->setBody($message)->setFrom($mailConfig->from_email, $mailConfig->from_name)->addTo($mailConfig->to_email, $mailConfig->to_name)->setSubject($mailConfig->subject);
     $transport = new Mail\Transport\Smtp(new Mail\Transport\SmtpOptions($config['smtp_config']));
     $transport->send($mail);
 }
Пример #14
0
 /**
  * @param Message $message
  */
 public function send(Message $message)
 {
     if (!count($message->getFrom())) {
         $message->setFrom('*****@*****.**', 'US Canine Scent Sports');
     }
     $transport = new Transport\Smtp();
     $transport->setOptions($this->transportOptions)->send($message);
 }
Пример #15
0
 public function flush()
 {
     $this->transport->setOptions($this->getSmtpOptions());
     foreach ($this->queue as $message) {
         $this->transport->send($message);
     }
     $this->queue = [];
 }
Пример #16
0
 public function getServiceConfig()
 {
     return array('factories' => array('mail.transport' => function ($serviceManager) {
         $config = $serviceManager->get('Config');
         $transport = new SmtpTransport();
         $transport->setOptions(new SmtpOptions($config['mail']['transport']['options']));
         return $transport;
     }));
 }
Пример #17
0
 public function testCanUseAuthenticationExtensionsViaPluginBroker()
 {
     $options = new SmtpOptions(array('connection_class' => 'login'));
     $transport = new Smtp($options);
     $connection = $transport->plugin($options->getConnectionClass(), array(array('username' => 'matthew', 'password' => 'password', 'host' => 'localhost')));
     $this->assertInstanceOf('Zend\\Mail\\Protocol\\Smtp\\Auth\\Login', $connection);
     $this->assertEquals('matthew', $connection->getUsername());
     $this->assertEquals('password', $connection->getPassword());
 }
Пример #18
0
 public function getServiceConfig()
 {
     return array('factories' => array('ZF2Base\\Mail\\Transport' => function ($sm) {
         $config = $sm->get('Config');
         $transport = new SmtpTransport();
         $options = new SmtpOptions($config['mail']);
         $transport->setOptions($options);
         return $transport;
     }));
 }
Пример #19
0
 public function testSendMinimalMail()
 {
     $headers = new Headers();
     $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200');
     $message = new Message();
     $message->setHeaders($headers)->setSender('*****@*****.**', 'Ralph Schindler')->setBody('testSendMailWithoutMinimalHeaders')->addTo('*****@*****.**', 'ZF DevTeam');
     $expectedMessage = "RSET\r\n" . "MAIL FROM:<*****@*****.**>\r\n" . "DATA\r\n" . "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n" . "Sender: Ralph Schindler <*****@*****.**>\r\n" . "To: ZF DevTeam <*****@*****.**>\r\n" . "\r\n" . "testSendMailWithoutMinimalHeaders\r\n" . ".\r\n";
     $this->transport->send($message);
     $this->assertEquals($expectedMessage, $this->connection->getLog());
 }
Пример #20
0
 public function sendMail($message)
 {
     $smtpOptions = new SmtpOptions();
     $smtpOptions->setHost('smtp.celeste.fr')->setName('smtp.celeste.fr');
     $transport = new Smtp($smtpOptions);
     try {
         $transport->send($message);
     } catch (\Exception $ex) {
     }
 }
Пример #21
0
 /**
  * Send mail
  */
 public function sendMail()
 {
     if (!$this->transport) {
         $this->transport = new Sendmail();
     }
     $this->getMailMessageObject()->setFrom($this->emailFrom);
     $this->getMailMessageObject()->setSubject($this->emailFrom);
     $this->getMailMessageObject()->setBody($this->emailFrom);
     $this->transport->send($this->getMailMessageObject());
 }
Пример #22
0
 public function testSendEscapedEmail()
 {
     $headers = new Headers();
     $headers->addHeaderLine('Date', 'Sun, 10 Jun 2012 20:07:24 +0200');
     $message = new Message();
     $message->setHeaders($headers)->setSender('*****@*****.**', 'Ralph Schindler')->setBody("This is a test\n.")->addTo('*****@*****.**', 'ZF DevTeam');
     $expectedMessage = "EHLO localhost\r\n" . "MAIL FROM:<*****@*****.**>\r\n" . "DATA\r\n" . "Date: Sun, 10 Jun 2012 20:07:24 +0200\r\n" . "Sender: Ralph Schindler <*****@*****.**>\r\n" . "To: ZF DevTeam <*****@*****.**>\r\n" . "\r\n" . "This is a test\r\n" . "..\r\n" . ".\r\n";
     $this->transport->send($message);
     $this->assertEquals($expectedMessage, $this->connection->getLog());
 }
Пример #23
0
 public function sendMail()
 {
     $message = new Message();
     $message->addTo('*****@*****.**')->addFrom('*****@*****.**')->setSubject('Greetings and Salutations!')->setBody("Sorry, I’m going to be late today!");
     // Setup SMTP transport using LOGIN authentication
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('name' => 'localhost.localdomain', 'host' => '127.0.0.1', 'connection_class' => 'login', 'connection_config' => array('username' => 'user', 'password' => 'pass')));
     $transport->setOptions($options);
     $transport->send($message);
 }
Пример #24
0
 public function getServiceConfig()
 {
     return array('factories' => array('Mailer' => function ($sm) {
         $config = $sm->get('Config');
         //print_r($config);die;
         $transport = new Smtp();
         $transport->setOptions(new SmtpOptions($config['mail']['transport']['options']));
         return $transport;
     }));
 }
 /**
  * Prepare SendEmail job
  * 
  * 
  * @uses SendEmailJob
  * 
  * @access public
  * @param ServiceLocatorInterface $serviceLocator
  * @return SendEmailJob
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     // Setup SMTP transport using LOGIN authentication
     $config = $serviceLocator->getServiceLocator()->get('Config');
     $options = new SmtpOptions($config['mail_settings']);
     $transport = new Smtp();
     $transport->setOptions($options);
     $job = new SendEmailJob($transport);
     return $job;
 }
Пример #26
0
 public function getServiceConfig()
 {
     return array('factories' => array('Zend\\Authentication\\AuthenticationService' => function ($serviceManager) {
         return $serviceManager->get('doctrine.authenticationservice.orm_default');
     }, 'mail.transport' => function (ServiceManager $serviceManager) {
         $config = $serviceManager->get('Config');
         $transport = new Smtp();
         $transport->setOptions(new SmtpOptions($config['mail']['transport']['options']));
         return $transport;
     }));
 }
Пример #27
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     $logger = $serviceLocator->get('Application\\Logger');
     $transport = new Smtp();
     $transport->setOptions(new SmtpOptions($config['mail']['transport']['options']));
     $mailer = new Mailer($transport);
     $mailer->setLogger($logger);
     $mailer->setRecipients($config['mailer']['recipients']);
     return $mailer;
 }
Пример #28
0
 public function getServiceConfig()
 {
     return array('factories' => array('SONUser\\Mail\\Transport' => function ($sm) {
         $config = $sm->get('Config');
         $transport = new SmtpTransport();
         $options = new SmtpOptions($config['mail']);
         $transport->setOptions($options);
         return $transport;
     }, 'SONUser\\Service\\User' => function ($sm) {
         return new Service\User($sm->get('Doctrine\\ORM\\EntityManager'), $sm->get('SONUser\\Mail\\Transport'), $sm->get('View'));
     }));
 }
Пример #29
0
 protected function createMessage(array $data)
 {
     $message = new \Zend\Mail\Message();
     $message->setBody($_POST['message']);
     $message->setFrom($_POST['email']);
     $message->setSubject(" contact message ");
     $message->addTo('*****@*****.**');
     $smtpOptions = new \Zend\Mail\Transport\SmtpOptions();
     $smtpOptions->setHost('smtp.gmail.com')->setConnectionClass('login')->setName('smtp.gmail.com')->setConnectionConfig(array('username' => '*****@*****.**', 'password' => 'Yatakafils1', 'ssl' => 'tls'));
     $transport = new \Zend\Mail\Transport\Smtp($smtpOptions);
     $transport->send($message);
 }
Пример #30
0
 public function sendEmailsFromQueue($developmentMode = false)
 {
     $transport = new SmtpTransport();
     $options = new SmtpOptions(array('name' => $this->config['smtp']['name'], 'host' => $this->config['smtp']['host'], 'port' => $this->config['smtp']['port']));
     /** GMAIL SMTP Test
     		$options = new \Zend\Mail\Transport\SmtpOptions();
     
     		$options->setHost('smtp.gmail.com')
                 ->setConnectionClass('login')
                 ->setName('smtp.gmail.com')
                 ->setPort(587)
                 ->setConnectionConfig(array(
                                    'username' => '<email>',
                                    'password' => '<1password > gmail smtp>',
                                    'ssl' => 'tls',
                                  )
                       );
     		*/
     $transport->setOptions($options);
     $entity = new $this->config['database']['entity']();
     $tableName = $this->entityManager->getClassMetadata(get_class($entity))->getTableName();
     $dql = 'SELECT m FROM ' . $this->config['database']['entity'] . ' m WHERE m.send = 0 AND m.scheduleDate < :now ORDER BY m.prio, m.createDate DESC';
     $query = $this->entityManager->createQuery($dql)->setParameter('now', date('Y-m-d H:i:s'))->setMaxResults($this->config['numberOfEmailsPerRun']);
     $queue = $query->getResult();
     foreach ($queue as $mail) {
         // In development mode we only send emails to predefined email addresses to prevent "strange" unrequested
         // emails to users.
         if ($developmentMode === true && !in_array($mail->getRecipientEmail(), $this->config['developmentEmails'])) {
             $this->entityManager->getConnection()->update($tableName, array('send' => 1, 'sendDate' => date('Y-m-d H:i:s')), array('id' => $mail->getId()));
             continue;
         }
         $message = new \Zend\Mail\Message();
         $message->addFrom($mail->getSenderEmail(), $mail->getSenderName())->addTo($mail->getRecipientEmail(), $mail->getRecipientName())->setSubject($mail->getSubject());
         if (trim($mail->getBodyHTML()) !== '') {
             $bodyPart = new \Zend\Mime\Message();
             $bodyMessage = new \Zend\Mime\Part($mail->getBodyHTML());
             $bodyMessage->type = 'text/html';
             $bodyPart->setParts(array($bodyMessage));
             $message->setBody($bodyPart);
             $message->setEncoding('UTF-8');
         } else {
             $message->setBody($mail->getBodyText());
         }
         try {
             $transport->send($message);
             $this->entityManager->getConnection()->update($tableName, array('send' => 1, 'sendDate' => date('Y-m-d H:i:s')), array('id' => $mail->getId()));
         } catch (\Exception $e) {
             $this->entityManager->getConnection()->update($tableName, array('send' => 2, 'error' => $e->getMessage()), array('id' => $mail->getId()));
             $this->queueNewMessage('MailAdmin', $this->config['adminEmail'], $e->getMessage(), $e->getMessage(), 'MailQueue Error', 9);
         }
     }
 }