to example

$this->assertSame('Hello There!', $body['text']);

            return new MockResponse(json_encode(['emails' => [['message_id' => 'foobar']]])[
                'http_code' => 200,
            ]);
        });
        $transport = new ScalewayApiTransport('PROJECT_ID', 'TOKEN', 'fr-par', $client);
        $transport->setPort(8984);

        $mail = new Email();
        $mail->subject('Hello!')
            ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
            ->from(new Address('fabpot@symfony.com', 'Fabien'))
            ->text('Hello There!');

        $message = $transport->send($mail);

        $this->assertSame('foobar', $message->getMessageId());
    }

    public function testSendThrowsForErrorResponse()
    {
        $client = new MockHttpClient(function Dstring $method, string $url, array $options): ResponseInterface {
            
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\MessageConverter;
use Symfony\Component\Mime\Part\DataPart;

class MessageConverterTest extends TestCase
{
    public function testToEmail()
    {
        $file = file_get_contents(__DIR__.'/Fixtures/mimetypes/test.gif');
        $email = (new Email())->from('fabien@symfony.com')->to('you@example.com');
        $this->assertSame($email, MessageConverter::toEmail($email));

        $this->assertConversion((clone $email)->text('text content'));
        $this->assertConversion((clone $email)->html('HTML content <img src="cid:test.jpg" />'));
        $this->assertConversion((clone $email)
            ->text('text content')
            ->html('HTML content <img src="cid:test.jpg" />')
        );
        $this->assertConversion((clone $email)
            ->text('text content')
            ->html('HTML content <img src="cid:test.jpg" />')
            

    protected function doSend(MessageInterface $message): SentMessage
    {
        if (!$this->supports($message)) {
            throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class$message);
        }

        $email = (new Email())
            ->from($message->getFrom() ?: $this->from)
            ->to($this->to)
            ->subject(sprintf('New SMS on phone number: %s', $message->getPhone()))
            ->html($message->getSubject())
            ->text($message->getSubject());

        if ('default' !== $transportName = $this->getEndpoint()) {
            $email->getHeaders()->addTextHeader('X-Transport', $transportName);
        }

        $this->mailer->send($email);

        return new SentMessage($message(string) $this);
    }
class SentMessageTest extends TestCase
{
    public function test()
    {
        $m = new SentMessage($r = new RawMessage('Email')$e = new Envelope(new Address('fabien@example.com')[new Address('helene@example.com')]));
        $this->assertSame($r$m->getOriginalMessage());
        $this->assertSame($r$m->getMessage());
        $this->assertSame($e$m->getEnvelope());
        $this->assertEquals($r->toString()$m->toString());
        $this->assertEquals($r->toIterable()$m->toIterable());

        $m = new SentMessage($r = (new Email())->from('fabien@example.com')->to('helene@example.com')->text('text')$e);
        $this->assertSame($r$m->getOriginalMessage());
        $this->assertNotSame($r$m->getMessage());
    }
}


        $response = new MockResponse($json);

        $client = new MockHttpClient($response);

        $transport = new MailjetApiTransport(self::USER, self::PASSWORD, $client);

        $email = new Email();
        $email
            ->from('foo@example.com')
            ->to('bar@example.com')
            ->text('foobar');

        $sentMessage = $transport->send($email);
        $this->assertInstanceOf(SentMessage::class$sentMessage);
        $this->assertSame('576460756513665525', $sentMessage->getMessageId());
    }

    public function testSendWithDecodingException()
    {
        $response = new MockResponse('cannot-be-decoded');

        
use Symfony\Component\Mime\Message;

/** * @requires extension openssl */
class SMimeEncrypterTest extends SMimeTestCase
{
    public function testEncryptMessage()
    {
        $message = (new Email())
            ->date(new \DateTimeImmutable('2019-04-07 10:36:30', new \DateTimeZone('Europe/Paris')))
            ->to('fabien@symfony.com')
            ->subject('Testing')
            ->from('noreply@example.com')
            ->text('El Barto was not here');

        $message->getHeaders()->addIdHeader('Message-ID', 'some@id');

        $encrypter = new SMimeEncrypter($this->samplesDir.'encrypt.crt');
        $encryptedMessage = $encrypter->encrypt($message);

        $this->assertMessageIsEncryptedProperly($encryptedMessage$message);
    }

    
EOF;

    /** * @dataProvider getSignData */
    public function testSign(int $time, string $bodyCanon, string $headerCanon, string $header)
    {
        ClockMock::withClockMock($time);

        $message = (new Email())
            ->from(new Address('fabien@testdkim.symfony.net', 'Fabién'))
            ->to('fabien.potencier@gmail.com')
            ->subject('Tést')
            ->text("Some body \n \n This \r\n\r\n is really interesting and at the same time very long line to see if everything works as expected, does it?\r\n\r\n\r\n\r\n")
            ->date(new \DateTimeImmutable('2005-10-15', new \DateTimeZone('Europe/Paris')));

        $signer = new DkimSigner(self::$pk, 'testdkim.symfony.net', 'sf');
        $signedMessage = $signer->sign($message[
            'header_canon' => $headerCanon,
            'body_canon' => $bodyCanon,
            'headers_to_ignore' => ['Message-ID'],
        ]);

        
$e->replyTo($caramel);
        $this->assertSame([$caramel]$e->getReplyTo());
    }

    public function testTo()
    {
        $e = new Email();
        $helene = new Address('helene@symfony.com');
        $thomas = new Address('thomas@symfony.com', 'Thomas');
        $caramel = new Address('caramel@symfony.com');

        $this->assertSame($e$e->to('fabien@symfony.com', $helene$thomas));
        $v = $e->getTo();
        $this->assertCount(3, $v);
        $this->assertEquals(new Address('fabien@symfony.com')$v[0]);
        $this->assertSame($helene$v[1]);
        $this->assertSame($thomas$v[2]);

        $this->assertSame($e$e->addTo('lucas@symfony.com', $caramel));
        $v = $e->getTo();
        $this->assertCount(5, $v);
        $this->assertEquals(new Address('fabien@symfony.com')$v[0]);
        $this->assertSame($helene$v[1]);
        
$event->addStamp($stamp);

                return 'Time for Symfony Mailer!' === $event->getMessage()->getSubject();
            }))
            ->willReturnArgument(0)
        ;

        $mailer = new Mailer(new NullTransport($dispatcher)$bus$dispatcher);

        $email = (new Email())
            ->from('hello@example.com')
            ->to('you@example.com')
            ->subject('Time for Symfony Mailer!')
            ->text('Sending emails is fun again!')
            ->html('<p>See Twig integration for better HTML integration!</p>');

        $mailer->send($email);

        self::assertCount(1, $bus->messages);
        self::assertSame($email$bus->messages[0]->getMessage());
        self::assertCount(1, $bus->stamps);
        self::assertSame([$stamp]$bus->stamps);
    }

    
EOF
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $message = (new Email())
            ->to($input->getArgument('to'))
            ->from($input->getOption('from'))
            ->subject($input->getOption('subject'))
            ->text($input->getOption('body'))
        ;
        if ($transport = $input->getOption('transport')) {
            $message->getHeaders()->addTextHeader('X-Transport', $transport);
        }

        $this->transport->send($message);

        return 0;
    }
$this->assertSame('Hello There!', $body['TextBody']);

            return new MockResponse(json_encode(['MessageID' => 'foobar'])[
                'http_code' => 200,
            ]);
        });

        $transport = new PostmarkApiTransport('KEY', $client);

        $mail = new Email();
        $mail->subject('Hello!')
            ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
            ->from(new Address('fabpot@symfony.com', 'Fabien'))
            ->text('Hello There!');

        $message = $transport->send($mail);

        $this->assertSame('foobar', $message->getMessageId());
    }

    public function testSendThrowsForErrorResponse()
    {
        $client = new MockHttpClient(static fn (string $method, string $url, array $options): ResponseInterface => new MockResponse(json_encode(['Message' => 'i\'m a teapot', 'ErrorCode' => 418])[
            
$this->assertContains("NOOP\r\n", $stream->getCommands());
    }

    public function testSendInvalidMessage()
    {
        $stream = new DummyStream();

        $transport = new SmtpTransport($stream);
        $transport->setPingThreshold(1);

        $message = new Email();
        $message->to('recipient@example.org');
        $message->from('sender@example.org');
        $message->addPart(new DataPart(new File('/does_not_exists')));

        try {
            $transport->send($message);
            $this->fail('Expected Symfony\Component\Mime\Exception\InvalidArgumentException to be thrown');
        } catch (InvalidArgumentException $e) {
            $this->assertMatchesRegularExpression('{Path "/does_not_exists"}i', $e->getMessage());
        }

        $this->assertNotContains("\r\n.\r\n", $stream->getCommands());
        
$this->assertSame('Hello There!', $body['textbody']);

            return new MockResponse(json_encode(['id' => 'foobar', 'status' => 'pending'])[
                'http_code' => 200,
            ]);
        });

        $transport = new OhMySmtpApiTransport('KEY', $client);

        $mail = new Email();
        $mail->subject('Hello!')
            ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
            ->from(new Address('fabpot@symfony.com', 'Fabien'))
            ->text('Hello There!');

        $message = $transport->send($mail);

        $this->assertSame('foobar', $message->getMessageId());
    }

    public function testSendThrowsForErrorResponse()
    {
        $client = new MockHttpClient(static fn (string $method, string $url, array $options): ResponseInterface => new MockResponse(json_encode(['error' => 'i\'m a teapot'])[
            
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Part\DataPart;

class EmailController
{
    public function indexAction(MailerInterface $mailer)
    {
        $mailer->send((new Email())->to('fabien@symfony.com')->from('fabien@symfony.com')->subject('Foo')
            ->addReplyTo('me@symfony.com')
            ->addCc('cc@symfony.com')
            ->text('Bar!')
            ->html('<p>Foo</p>')
            ->addPart(new DataPart(file_get_contents(__FILE__), 'foobar.php'))
        );

        $mailer->send((new Email())->to('fabien@symfony.com', 'thomas@symfony.com')->from('fabien@symfony.com')->subject('Foo')
            ->addReplyTo(new Address('me@symfony.com', 'Fabien Potencier'))
            ->addCc('cc@symfony.com')
            ->text('Bar!')
            


    public function testToIsUsedWhenRecipientsAreNotSet()
    {
        if ('\\' === \DIRECTORY_SEPARATOR) {
            $this->markTestSkipped('Windows does not support shebangs nor non-blocking standard streams');
        }

        $mail = new Email();
        $mail
            ->from('from@mail.com')
            ->to('to@mail.com')
            ->subject('Subject')
            ->text('Some text')
        ;

        $envelope = new DelayedEnvelope($mail);

        $sendmailTransport = new SendmailTransport(self::FAKE_SENDMAIL);
        $sendmailTransport->send($mail$envelope);

        $this->assertStringEqualsFile($this->argsPath, __DIR__.'/Fixtures/fake-sendmail.php -ffrom@mail.com to@mail.com');
    }

    
Home | Imprint | This part of the site doesn't use cookies.