getOriginalMessage example

$message = new DummyMessage();
        $sentMessage = new SentMessage($message, 'any');

        $this->transport
            ->expects($this->once())
            ->method('send')
            ->with($message)
            ->willReturn($sentMessage);

        $texter = new Texter($this->transport);
        $this->assertSame($sentMessage$texter->send($message));
        $this->assertSame($message$sentMessage->getOriginalMessage());
    }

    public function testSendWithBus()
    {
        $message = new DummyMessage();

        $this->transport
            ->expects($this->never())
            ->method('send')
            ->with($message);

        
'one' => $one = $this->createMock(TransportInterface::class),
        ]);

        $message = new ChatMessage('subject');

        $one->method('supports')->with($message)->willReturn(true);

        $one->expects($this->once())->method('send')->willReturn(new SentMessage($message, 'one'));

        $sentMessage = $transports->send($message);

        $this->assertSame($message$sentMessage->getOriginalMessage());
        $this->assertSame('one', $sentMessage->getTransport());
    }

    public function testSendToFirstSupportedTransportIfMessageDoesNotDefineATransport()
    {
        $transports = new Transports([
            'one' => $one = $this->createMock(TransportInterface::class),
            'two' => $two = $this->createMock(TransportInterface::class),
        ]);

        $message = new ChatMessage('subject');

        
$request = [
            'Destination' => new Destination([
                'ToAddresses' => $this->stringifyAddresses($message->getEnvelope()->getRecipients()),
            ]),
            'Content' => [
                'Raw' => [
                    'Data' => $message->toString(),
                ],
            ],
        ];

        if (($message->getOriginalMessage() instanceof Message)
            && $configurationSetHeader = $message->getOriginalMessage()->getHeaders()->get('X-SES-CONFIGURATION-SET')) {
            $request['ConfigurationSetName'] = $configurationSetHeader->getBodyAsString();
        }
        if (($message->getOriginalMessage() instanceof Message)
            && $sourceArnHeader = $message->getOriginalMessage()->getHeaders()->get('X-SES-SOURCE-ARN')) {
            $request['FromEmailAddressIdentityArn'] = $sourceArnHeader->getBodyAsString();
        }
        if ($message->getOriginalMessage() instanceof Message) {
            foreach ($message->getOriginalMessage()->getHeaders()->all() as $header) {
                if ($header instanceof MetadataHeader) {
                    $request['EmailTags'][] = ['Name' => $header->getKey(), 'Value' => $header->getValue()];
                }
$sentMessage = new SentMessage($message, 'any');

        $this->transport
            ->expects($this->once())
            ->method('send')
            ->with($message)
            ->willReturn($sentMessage);

        $chatter = new Chatter($this->transport);
        $this->assertSame($sentMessage$chatter->send($message));
        $this->assertSame($message$sentMessage->getOriginalMessage());
    }

    public function testSendWithBus()
    {
        $message = new DummyMessage();

        $this->transport
            ->expects($this->never())
            ->method('send')
            ->with($message);

        
TXT,
            $sentMessage->toString()
        );
        $this->assertInstanceOf(Email::class$sentMessage->getOriginalMessage());
        $this->assertEquals([new Address('bcc@example.com')]$sentMessage->getOriginalMessage()->getBcc());
    }

    public function testSendEmailWithAttachmentsWithSuccess()
    {
        $email = $this->basicValidEmail()
            ->text('foobar')
            ->addPart(new DataPart('some attachment', 'attachment.txt', 'text/plain'))
            ->addPart((new DataPart('some inline attachment', 'inline.txt', 'text/plain'))->asInline())
        ;

        
$host = $endpoint['host'].($endpoint['port'] ?? null ? ':'.$endpoint['port'] : '');
        } else {
            $host = $configuration->get('region');
        }

        return sprintf('ses+api://%s@%s', $configuration->get('accessKeyId')$host);
    }

    protected function getRequest(SentMessage $message): SendEmailRequest
    {
        try {
            $email = MessageConverter::toEmail($message->getOriginalMessage());
        } catch (\Exception $e) {
            throw new RuntimeException(sprintf('Unable to send message with the "%s" transport: ', __CLASS__).$e->getMessage(), 0, $e);
        }

        if ($email->getAttachments()) {
            return parent::getRequest($message);
        }

        $envelope = $message->getEnvelope();

        $request = [
            
/** * @author Fabien Potencier <fabien@symfony.com> */
abstract class AbstractApiTransport extends AbstractHttpTransport
{
    abstract protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $envelope): ResponseInterface;

    protected function doSendHttp(SentMessage $message): ResponseInterface
    {
        try {
            $email = MessageConverter::toEmail($message->getOriginalMessage());
        } catch (\Exception $e) {
            throw new RuntimeException(sprintf('Unable to send message with the "%s" transport: ', __CLASS__).$e->getMessage(), 0, $e);
        }

        return $this->doSendApi($message$email$message->getEnvelope());
    }

    /** * @return Address[] */
    protected function getRecipients(Email $email, Envelope $envelope): array
    {
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\SentMessage;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\RawMessage;

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());
    }
}
Home | Imprint | This part of the site doesn't use cookies.