getMessageId example

$transport = new MailgunApiTransport('ACCESS_KEY', 'symfony', 'us-east-1', $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 testSendWithMultipleTagHeaders()
    {
        $client = new MockHttpClient(function Dstring $method, string $url, array $options): ResponseInterface {
            $content = '';
            while ($chunk = $options['body']()) {
                $content .= $chunk;
            }

            $this->assertStringContainsString("Content-Disposition: form-data; name=\"o:tag\"\r\n\r\npassword-reset\r\n", $content);
            
$transport = $this->createTransport(new MockHttpClient(function Dstring $method, string $url, array $options) {
            $this->assertSame('POST', $method);
            $this->assertSame('https://host.test/api/v1/statuses', $url);
            $this->assertSame('{"status":"Hello World!"}', $options['body']);
            $this->assertArrayHasKey('authorization', $options['normalized_headers']);

            return new MockResponse('{"id":"103254962155278888"}');
        }));

        $result = $transport->send(new ChatMessage('Hello World!'));

        $this->assertSame('103254962155278888', $result->getMessageId());
    }

    public function testStatusWithPoll()
    {
        $transport = $this->createTransport(new MockHttpClient(function Dstring $method, string $url, array $options) {
            $this->assertSame('POST', $method);
            $this->assertSame('https://host.test/api/v1/statuses', $url);
            $this->assertSame('{"poll":{"options":["choice1","choice2"],"expires_in":3600},"status":"Hello World!"}', $options['body']);
            $this->assertArrayHasKey('authorization', $options['normalized_headers']);

            return new MockResponse('{"id":"103254962155278888"}');
        }));
$client = new MockHttpClient(function Dstring $method, string $url) use ($response): ResponseInterface {
            self::assertSame('POST', $method);
            self::assertSame('https://rest.smsmode.com/sms/v1/messages', $url);

            return $response;
        });

        $transport = $this->createTransport($client$from);

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

        self::assertSame('foo', $sentMessage->getMessageId());
    }

    public function testHttpClientHasMandatoryHeaderAccept()
    {
        $message = new SmsMessage('+33612345678', 'Hello!');

        $response = $this->createMock(ResponseInterface::class);
        $response->expects(self::exactly(2))->method('getStatusCode')->willReturn(201);
        $response->expects(self::once())->method('getContent')->willReturn(json_encode(['messageId' => 'foo']));

        $transport = $this->createTransport(new MockHttpClient(function Dstring $method, string $url, array $options) use ($response): ResponseInterface {
            
$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 {
            return new MockResponse(json_encode(['message' => 'i\'m a teapot'])[
                'http_code' => 418,
                'response_headers' => [
                    'content-type' => 'application/json',
                ],
            ]);
        });
$sentMessage->toString()
        );
    }

    public function testSentMessageShouldCaptureInfobipMessageId()
    {
        $this->response = new MockResponse('{"messages": [{"messageId": "somexternalMessageId0"}]}');
        $email = $this->basicValidEmail();

        $sentMessage = $this->transport->send($email);

        $this->assertSame('somexternalMessageId0', $sentMessage->getMessageId());
    }

    public function testInfobipResponseShouldNotBeEmpty()
    {
        $this->response = new MockResponse();
        $email = $this->basicValidEmail();

        $this->expectException(HttpTransportException::class);
        $this->expectExceptionMessage('Unable to send an email: ""');

        $this->transport->send($email);
    }
$response,
            $expectedBody
        ): ResponseInterface {
            $this->assertSame($expectedBody$options['body']);

            return $response;
        });
        $transport = self::createTransport($client);

        $sentMessage = $transport->send(new PushMessage($messageSubject$messageContent));

        $this->assertSame('uuid', $sentMessage->getMessageId());
    }

    public function testSendWithNotification()
    {
        $messageSubject = 'testMessageSubject';
        $messageContent = 'testMessageContent';

        $response = $this->createMock(ResponseInterface::class);

        $response->expects($this->exactly(2))
            ->method('getStatusCode')
            
$transport = new MailPaceApiTransport('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'])[
            'http_code' => 418,
            'response_headers' => [
                'content-type' => 'application/json',
            ],
        ]));
        $transport = new MailPaceApiTransport('KEY', $client);
        
/** * @throws TransportExceptionInterface */
    public function testSendMessage()
    {
        $successReply = 'Sending,L5 Send SMS to:0123; ID:'.($messageId = 'dj282jjs8');

        $mockClient = new MockHttpClient(new MockResponse($successReply));
        $sentMessage = self::createTransport($mockClient)->send(new SmsMessage('0123', 'Test'));

        $this->assertSame($messageId$sentMessage->getMessageId());
    }

    /** * @dataProvider goipErrorsProvider * * @throws TransportExceptionInterface */
    public function testSendMessageWithUnsuccessfulReplyFromGoipThrows(string $goipError)
    {
        $this->expectException(TransportException::class);
        $this->expectExceptionMessage(sprintf('Could not send the message through GoIP. Response: "%s".', $goipError));

        
$prefix.'is_redelivery' => $c->isRedelivery(),
            $prefix.'exchange_name' => $c->getExchangeName(),
            $prefix.'routing_key' => $c->getRoutingKey(),
            $prefix.'content_type' => $c->getContentType(),
            $prefix.'content_encoding' => $c->getContentEncoding(),
            $prefix.'headers' => $c->getHeaders(),
            $prefix.'delivery_mode' => $deliveryMode,
            $prefix.'priority' => $c->getPriority(),
            $prefix.'correlation_id' => $c->getCorrelationId(),
            $prefix.'reply_to' => $c->getReplyTo(),
            $prefix.'expiration' => $c->getExpiration(),
            $prefix.'message_id' => $c->getMessageId(),
            $prefix.'timestamp' => $c->getTimeStamp(),
            $prefix.'type' => $c->getType(),
            $prefix.'user_id' => $c->getUserId(),
            $prefix.'app_id' => $c->getAppId(),
        ];

        return $a;
    }

    private static function extractFlags(int $flags): ConstStub
    {
        
->from(new Address('fabpot@symfony.com', 'Fabien'))
            ->text('Hello here!')
            ->html('Hello there!')
            ->addCc('foo@bar.fr')
            ->addBcc('foo@bar.fr')
            ->addReplyTo('foo@bar.fr')
            ->addPart(new DataPart('body'))
        ;

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

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

    public function send($transport = null)
    {
        Shopware()->Events()->notify(
            'Enlight_Components_Mail_Send',
            [
                'mail' => $this,
                'transport' => $transport,
            ]
        );

        if (!$this->getMessageId()) {
            $this->setMessageId();
        }

        return parent::send($transport);
    }
}
private function runWorker(string $failureTransportName, ReceiverInterface $receiver, SymfonyStyle $io, bool $shouldForce): int
    {
        $count = 0;
        $listener = function DWorkerMessageReceivedEvent $messageReceivedEvent) use ($io$receiver$shouldForce, &$count) {
            ++$count;
            $envelope = $messageReceivedEvent->getEnvelope();

            $this->displaySingleMessage($envelope$io);

            if ($envelope->last(MessageDecodingFailedStamp::class)) {
                throw new \RuntimeException(sprintf('The message with id "%s" could not decoded, it can only be shown or removed.', $this->getMessageId($envelope) ?? '?'));
            }

            $shouldHandle = $shouldForce || 'retry' === $io->choice('Please select an action', ['retry', 'delete'], 'retry');

            if ($shouldHandle) {
                return;
            }

            $messageReceivedEvent->shouldHandle(false);
            $receiver->reject($envelope);
        };
        
$transport = new MandrillApiTransport('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(fn (string $method, string $url, array $options): ResponseInterface => new MockResponse(json_encode(['status' => 'error', 'message' => 'i\'m a teapot', 'code' => 418])[
            'http_code' => 418,
        ]));

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

        $mail = new Email();
        
if ($classFilter && $classFilter !== $currentClassName) {
                    continue;
                }

                /** @var RedeliveryStamp|null $lastRedeliveryStamp */
                $lastRedeliveryStamp = $envelope->last(RedeliveryStamp::class);
                /** @var ErrorDetailsStamp|null $lastErrorDetailsStamp */
                $lastErrorDetailsStamp = $envelope->last(ErrorDetailsStamp::class);

                $rows[] = [
                    $this->getMessageId($envelope),
                    $currentClassName,
                    null === $lastRedeliveryStamp ? '' : $lastRedeliveryStamp->getRedeliveredAt()->format('Y-m-d H:i:s'),
                    $lastErrorDetailsStamp?->getExceptionMessage() ?? '',
                ];
            }
        } finally {
            $this->phpSerializer?->rejectPhpIncompleteClass();
        }

        $rowsCount = \count($rows);

        
 $body);

            return $response;
        });

        $message = new SmsMessage('380931234567', 'Тест/Test');

        $transport = self::createTransport($client);
        $sentMessage = $transport->send($message);

        self::assertInstanceOf(SentMessage::class$sentMessage);
        self::assertSame('f83f8868-5e46-c6cf-e4fb-615e5a293754', $sentMessage->getMessageId());
    }

    public function testFailedSend()
    {
        $response = $this->createMock(ResponseInterface::class);
        $response
            ->expects(self::exactly(2))
            ->method('getStatusCode')
            ->willReturn(400)
        ;
        $response
            
Home | Imprint | This part of the site doesn't use cookies.