コード例 #1
0
 /**
  * @When I send email to :email with message :body
  */
 public function iSendEmailWithMessage($email, $body)
 {
     $message = new \Swift_Message('Subject', $body);
     $message->setSender('*****@*****.**');
     $message->setTo($email);
     $this->sendEmail($message);
 }
コード例 #2
0
ファイル: UserForgot.php プロジェクト: Monori/imgservice
 public function __construct()
 {
     parent::__construct();
     $this->prependSiteTitle(lang('Recover log in'));
     if ($this->isPostBack()) {
         $this->post->email->addValidation(new ValidateInputNotNullOrEmpty());
         if (!$this->hasErrors()) {
             $user = ModelUser::getByUsername($this->input('email'));
             if (!$user->hasRow()) {
                 $this->setMessage('No user found', 'warning');
                 response()->refresh();
             }
             if (!$this->hasErrors()) {
                 $reset = new UserReset($user->id);
                 $reset->save();
                 // TODO: Move this shit to seperate html template
                 $text = "Dear customer!\n\nYou are receiving this mail, because you (or someone else) has requested a password reset for your user on NinjaImg.com.\n\nTo continue with the password reset, please click the link below to confirm the reset:\n\n" . sprintf('https://%s/reset/%s', $_SERVER['HTTP_HOST'], $reset->key) . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team";
                 $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
                 $swift = \Swift_Mailer::newInstance($transport);
                 $message = new \Swift_Message(lang('Confirm password reset on NinjaImg'));
                 $message->setFrom(env('MAIL_FROM'));
                 $message->setSender(env('MAIL_FROM'));
                 $message->setReplyTo(env('MAIL_FROM'));
                 $message->setBody($text, 'text/plain');
                 $message->setTo($user->username);
                 $swift->send($message);
                 $this->setMessage('A password reset link has been sent to your e-mail', 'success');
                 // Send mail to user confirming reset...
                 // Maybe show message with text that are active even when session disappear
                 response()->refresh();
             }
         }
     }
 }
コード例 #3
0
ファイル: UserReset.php プロジェクト: Monori/imgservice
 public function __construct($key)
 {
     parent::__construct();
     $newPassword = uniqid();
     $reset = \Pecee\Model\User\UserReset::confirm($key, $newPassword);
     if ($reset) {
         $user = ModelUser::getById($reset);
         if ($user->hasRow()) {
             // Send mail with new password
             // TODO: Move this shit to separate html template
             $user->setEmailConfirmed(true);
             $user->update();
             $text = "Dear customer!\n\nWe've reset your password - you can login with your e-mail and the new password provided below:\nNew password: "******"\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team";
             $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
             $swift = \Swift_Mailer::newInstance($transport);
             $message = new \Swift_Message(lang('New password for NinjaImg'));
             $message->setFrom(env('MAIL_FROM'));
             $message->setSender(env('MAIL_FROM'));
             $message->setReplyTo(env('MAIL_FROM'));
             $message->setBody($text, 'text/plain');
             $message->setTo($user->username);
             $swift->send($message);
             $this->setMessage('A new password has been sent to your e-mail.', 'success');
             redirect(url('user.login'));
         }
         redirect(url('home'));
     }
 }
コード例 #4
0
ファイル: global_helpers.php プロジェクト: Monori/imgservice
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);
}
コード例 #5
0
ファイル: Account.php プロジェクト: Monori/imgservice
 protected function inviteUser()
 {
     if ($this->input('email')) {
         if ($this->currentUser->getRole() !== UserRole::TYPE_OWNER) {
             $this->setError(lang('You dont have permissions to invite users'));
             response()->refresh();
         }
         $this->post->email->addValidation([new ValidateInputNotNullOrEmpty(), new ValidateInputEmail()]);
         $this->post->role->addValidation(new ValidateInputNotNullOrEmpty());
         if (!$this->hasErrors()) {
             $user = ModelUser::getByUsername($this->input('email'));
             if ($user->hasRow() && $user->hasAccess($this->activeOrganisation->id)) {
                 if ($user->getRole() === $this->input('role')) {
                     $this->setMessage(lang('The user already has access to this organisation'), 'danger');
                 } else {
                     $user->setRole($this->input('role'));
                     $this->setMessage(lang('The role has been updated'), 'success');
                     // TODO: sent mail notifying about role-change
                 }
                 response()->refresh();
             }
             // Save invitation
             $invitation = new OrganisationInvite();
             $invitation->user_id = $this->currentUser->id;
             $invitation->email = $this->input('email');
             $invitation->organisation_id = $this->activeOrganisation->id;
             $invitation->role = $this->input('role');
             $invitation->save();
             // This point we send out a confirmation mail to accept the organisation invite.
             // TODO: move this shit to separate template
             $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
             $swift = \Swift_Mailer::newInstance($transport);
             $message = new \Swift_Message(lang('Invite to join ' . $this->activeOrganisation->name . ' on NinjaImg'));
             $message->setFrom(env('MAIL_FROM'));
             $message->setSender(env('MAIL_FROM'));
             $message->setReplyTo(env('MAIL_FROM'));
             $message->setBody("Dear customer!\n\n{$this->currentUser->data->name} has invited you to join the organisation {$this->activeOrganisation->name} on NinjaImg!\n\nClick on the link below to accept the invite:\nhttps://{$_SERVER['HTTP_HOST']}" . url('user.register') . "?email=" . $this->input('email') . "\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team", 'text/plain');
             $message->setTo($this->input('email'));
             $swift->send($message);
             $this->setMessage('An invite has been sent to the user.', 'success');
         }
     }
 }
コード例 #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var $transport \Swift_Transport */
     $transport = $this->getContainer()->get('swiftmailer.transport.real');
     if (!$transport->isStarted()) {
         $transport->start();
     }
     $spoolPath = sprintf('%s/*/', $this->getContainer()->getParameter('swiftmailer.spool.path'));
     $finder = Finder::create()->in($spoolPath)->name('*.sending');
     $parameters = $this->getContainer()->getParameter('emails');
     $parameters = $parameters['error'];
     foreach ($finder as $failedFile) {
         // rename the file, so no other process tries to find it
         $tmpFilename = $failedFile . '.finalretry';
         rename($failedFile, $tmpFilename);
         /** @var $message \Swift_Message */
         $message = unserialize(file_get_contents($tmpFilename));
         $output->writeln(sprintf('Retrying <info>%s</info> to <info>%s</info>', $message->getSubject(), implode(', ', array_keys($message->getTo()))));
         $errorContent = null;
         try {
             if ($transport->send($message)) {
                 $output->writeln('Sent!');
             } else {
                 $errorContent = sprintf("Un email n'a pas pu être envoyé aux adresses : %s\n");
             }
         } catch (\Swift_TransportException $e) {
             $errorContent = sprintf("Erreur lors de l'envoi d'un email aux adresses : %s\nErreur rencontrée : %s\n", implode(', ', $message->getTo()), $e->getMessage());
         }
         if ($errorContent) {
             $errorMessage = new \Swift_Message('[SEH Site Portail] Erreur lors de l\'envoi d\'un email', $errorContent . "Contenu du mail :\n" . $message->getBody());
             $errorMessage->setTo($parameters['to']);
             $errorMessage->setSender($parameters['sender']);
             try {
                 $transport->send($errorMessage);
             } catch (\Exception $e) {
                 $this->getContainer()->get('logger')->error($errorContent);
             }
             $output->writeln('<error>Send failed - deleting spooled message</error>');
         }
         // delete the file, either because it sent, or because it failed
         unlink($tmpFilename);
     }
 }
コード例 #7
0
ファイル: Invoices.php プロジェクト: Monori/imgservice
 protected function sendCustomerMail(OrganisationInvoice $invoice)
 {
     $users = ModelUser::getByOrganisationId($this->organisation->id, UserRole::TYPE_OWNER);
     if ($users->hasRows()) {
         foreach ($users as $user) {
             $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
             $swift = \Swift_Mailer::newInstance($transport);
             $message = new \Swift_Message(lang('New invoice available for ' . $this->organisation->name));
             $currency = ModelSettings::getInstance()->data->default_currency_character;
             $message->setFrom(env('MAIL_FROM'));
             $message->setSender(env('MAIL_FROM'));
             $message->setReplyTo(env('MAIL_FROM'));
             $message->setBody("Dear {$user->data->name}!\n\nAttached is the latest invoice from NinjaImg.\n\nThe amount for invoice {$invoice->invoice_id} is {$invoice->amount_total}{$currency} with payment date {$invoice->due_date}.\n\nYou can always view your invoices at your controlpanel on ninjaimg.com.\n\nThanks for supporting our service, we really appreciate it!\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team", 'text/plain');
             $message->setTo($user->username);
             $attachment = new \Swift_Attachment(file_get_contents($invoice->path), basename($invoice->path), File::getMime($invoice->path));
             $message->attach($attachment);
             $swift->send($message);
         }
     }
 }
コード例 #8
0
    /**
     * Prepare the email message.
     */
    public function processEmail()
    {
        $this->count = 1;
        $mail = new Swift_Message();
        $mail->setContentType('text/plain');
        $mail->setCharset('utf-8');
        if ($this->getOption('use_complete_template', true)) {
            $mail->setBody(sprintf(<<<EOF
------
%s - %s
------
%s
------
EOF
, $this->options['name'], $this->options['email'], $this->options['message']));
        } else {
            $mail->setBody($this->options['message']);
        }
        $mail->setSender(array(sfPlop::get('sf_plop_messaging_from_email') => sfPlop::get('sf_plop_messaging_from_name')));
        $mail->setFrom(array($this->options['email'] => $this->options['name']));
        if ($this->getOption('copy')) {
            $mail->setCc(array($this->options['email'] => $this->options['name']));
            $this->count++;
        }
        if (is_integer($this->getOption('receiver'))) {
            $receiver = sfGuardUserProfilePeer::retrieveByPK($this->getOption('receiver'));
            if ($receiver) {
                $mail->setTo(array($receiver->getEmail() => $receiver->getFullName()));
            } else {
                $mail->setTo(array(sfPlop::get('sf_plop_messaging_to_email') => sfPlop::get('sf_plop_messaging_to_name')));
            }
        } else {
            $mail->setTo(array(sfPlop::get('sf_plop_messaging_to_email') => sfPlop::get('sf_plop_messaging_to_name')));
        }
        if ($this->getOption('subject')) {
            $mail->setSubject($this->getOption('subject'));
        } else {
            $mail->setSubject(sfPlop::get('sf_plop_messaging_subject'));
        }
        $this->mail = $mail;
    }
コード例 #9
0
ファイル: UserRegister.php プロジェクト: Monori/imgservice
 protected function invitationAcceptedMail(OrganisationInvite $invite, ModelOrganisation $organisation, ModelUser $user)
 {
     $senderUser = ModelUser::getById($invite->user_id);
     if ($senderUser->hasRow() && !$senderUser->deleted) {
         $transport = \Swift_SendmailTransport::newInstance(env('MAIL_TRANSPORT') . ' -bs');
         $swift = \Swift_Mailer::newInstance($transport);
         $message = new \Swift_Message(lang('Invitation to ' . $organisation->name . ' accepted'));
         $message->setFrom(env('MAIL_FROM'));
         $message->setSender(env('MAIL_FROM'));
         $message->setReplyTo(env('MAIL_FROM'));
         $message->setBody("Dear {$senderUser->data->name}!\n\nWe are writing to inform you, that {$user->data->name} has just accepted your invitation to join the organisation {$organisation->name} on NinjaImg.\n\nIf you have any questions, feel free to contact us any time.\n\nKind regards,\nThe NinjaImg Team", 'text/plain');
         $message->setTo($senderUser->username);
         $swift->send($message);
     }
 }
コード例 #10
0
ファイル: Message.php プロジェクト: nova-framework/cms
 /**
  * Set the "sender" of the message.
  *
  * @param  string  $address
  * @param  string  $name
  * @return $this
  */
 public function sender($address, $name = null)
 {
     $this->swift->setSender($address, $name);
     return $this;
 }
コード例 #11
0
 private function createFakeFailedMessageFiles($count = 1)
 {
     $targetDir = __DIR__ . "/mock.spool.path/";
     $i = 0;
     while ($i < $count) {
         $random = md5(date('now')) . $count . rand(0, 10000000);
         $filename = $targetDir . "{$random}.sending";
         $msg = new \Swift_Message();
         $msg->setTo("*****@*****.**");
         $msg->setBody("random file {$random} bla bla.");
         $msg->setSubject("subject blabbla");
         $msg->setSender("*****@*****.**");
         $ser = serialize($msg);
         $filehandle = fopen($filename, "w");
         fwrite($filehandle, $ser);
         fclose($filehandle);
         $i++;
     }
     // make sure the right number of files has been created.
     $fileCount = 0;
     $targetDirHandle = opendir($targetDir);
     while (($file = readdir($targetDirHandle)) !== false) {
         $fileCount++;
     }
     $this->assertEquals($count + 3, $fileCount, "Exactly {$count} + 2 files (*.sending, '.', '..' and '.keepMe') expected in this directory( {$targetDir} ).");
 }
コード例 #12
0
ファイル: Message.php プロジェクト: cawaphp/email
 /**
  * {@inheritdoc}
  *
  * @return $this|self
  */
 public function setSender($address, $name = null) : self
 {
     $this->message->setSender($address, $name);
     return $this;
 }
コード例 #13
0
ファイル: Message.php プロジェクト: Webiny/Framework
 public function setSender(Email $sender)
 {
     $this->message->setSender($sender->email, $sender->name);
     return $this;
 }
コード例 #14
0
 /**
  * Set the sender of this message.
  *
  * This does not override the From field, but it has a higher significance.
  *
  * @param string $address
  * @param string $name optional
  * @return \TYPO3\CMS\Core\Mail\MailMessage
  */
 public function setSender($address, $name = null)
 {
     $address = $this->idnaEncodeAddresses($address);
     return parent::setSender($address, $name);
 }
コード例 #15
-1
ファイル: Bug34Test.php プロジェクト: Amunak/swiftmailer
 public function testEmbeddedFilesWithMultipartDataCreateMultipartRelatedContentAsAnAlternative()
 {
     $message = new Swift_Message();
     $message->setCharset('utf-8');
     $message->setSubject('test subject');
     $message->addPart('plain part', 'text/plain');
     $image = new Swift_Image('<image data>', 'image.gif', 'image/gif');
     $cid = $message->embed($image);
     $message->setBody('<img src="' . $cid . '" />', 'text/html');
     $message->setTo(array('*****@*****.**' => 'User'));
     $message->setFrom(array('*****@*****.**' => 'Other'));
     $message->setSender(array('*****@*****.**' => 'Other'));
     $id = $message->getId();
     $date = preg_quote(date('r', $message->getDate()), '~');
     $boundary = $message->getBoundary();
     $cidVal = $image->getId();
     $this->assertRegExp('~^' . 'Sender: Other <*****@*****.**>' . "\r\n" . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: Other <*****@*****.**>' . "\r\n" . 'To: User <*****@*****.**>' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: multipart/alternative;' . "\r\n" . ' boundary="' . $boundary . '"' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'plain part' . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: multipart/related;' . "\r\n" . ' boundary="(.*?)"' . "\r\n" . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: text/html; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . '<img.*?/>' . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: image/gif; name=image.gif' . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: inline; filename=image.gif' . "\r\n" . 'Content-ID: <' . $cidVal . '>' . "\r\n" . "\r\n" . preg_quote(base64_encode('<image data>'), '~') . "\r\n\r\n" . '--\\1--' . "\r\n" . "\r\n\r\n" . '--' . $boundary . '--' . "\r\n" . '$~D', $message->toString());
 }
コード例 #16
-2
 public function testHTMLPartAppearsLastEvenWhenAttachmentsAdded()
 {
     $message = new Swift_Message();
     $message->setCharset('utf-8');
     $message->setSubject('test subject');
     $message->addPart('plain part', 'text/plain');
     $attachment = new Swift_Attachment('<data>', 'image.gif', 'image/gif');
     $message->attach($attachment);
     $message->setBody('HTML part', 'text/html');
     $message->setTo(array('*****@*****.**' => 'User'));
     $message->setFrom(array('*****@*****.**' => 'Other'));
     $message->setSender(array('*****@*****.**' => 'Other'));
     $id = $message->getId();
     $date = preg_quote($message->getDate()->format('r'), '~');
     $boundary = $message->getBoundary();
     $this->assertRegExp('~^' . 'Sender: Other <*****@*****.**>' . "\r\n" . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: Other <*****@*****.**>' . "\r\n" . 'To: User <*****@*****.**>' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-Type: multipart/mixed;' . "\r\n" . ' boundary="' . $boundary . '"' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: multipart/alternative;' . "\r\n" . ' boundary="(.*?)"' . "\r\n" . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: text/plain; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'plain part' . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: text/html; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'HTML part' . "\r\n\r\n" . '--\\1--' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: image/gif; name=image.gif' . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: attachment; filename=image.gif' . "\r\n" . "\r\n" . preg_quote(base64_encode('<data>'), '~') . "\r\n\r\n" . '--' . $boundary . '--' . "\r\n" . '$~D', $message->toString());
 }