MetadataHeader example

$transport = new SesHttpAsyncAwsTransport(new SesClient(Configuration::create([])new NullProvider()$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!');

        $mail->getHeaders()->addTextHeader('X-SES-CONFIGURATION-SET', 'aws-configuration-set-name');
        $mail->getHeaders()->addTextHeader('X-SES-SOURCE-ARN', 'aws-source-arn');
        $mail->getHeaders()->add(new MetadataHeader('tagName1', 'tag Value1'));
        $mail->getHeaders()->add(new MetadataHeader('tagName2', 'tag Value2'));

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

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

    public function testSendThrowsForErrorResponse()
    {
        $client = new MockHttpClient(function Dstring $method, string $url, array $options): ResponseInterface {
            $json = json_encode([
                
$this->expectException(HttpTransportException::class);
        $this->expectExceptionMessage('Unable to send an email: i\'m a teapot (code 418).');
        $transport->send($mail);
    }

    public function testTagAndMetadataHeaders()
    {
        $email = new Email();
        $email->getHeaders()->addTextHeader('foo', 'bar');
        $email->getHeaders()->add(new TagHeader('password-reset,user'));
        $email->getHeaders()->add(new TagHeader('another'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));

        $transport = new MandrillHttpTransport('key');
        $method = new \ReflectionMethod(MandrillHttpTransport::class, 'addMandrillHeaders');
        $method->invoke($transport$email);

        $this->assertCount(3, $email->getHeaders()->toArray());
        $this->assertSame('foo: bar', $email->getHeaders()->get('FOO')->toString());
        $this->assertSame('X-MC-Tags: password-reset,user,another', $email->getHeaders()->get('X-MC-Tags')->toString());
        $this->assertSame('X-MC-Metadata: '.json_encode(['Color' => 'blue', 'Client-ID' => '12345'])$email->getHeaders()->get('X-MC-Metadata')->toString());
    }
}
$this->assertArrayHasKey('personalizations', $payload);
        $this->assertArrayHasKey('to', $payload['personalizations'][0]);
        $this->assertArrayHasKey('email', $payload['personalizations'][0]['to'][0]);
        $this->assertCount(1, $payload['personalizations'][0]['to']);
        $this->assertSame($envelopeTo$payload['personalizations'][0]['to'][0]['email']);
    }

    public function testTagAndMetadataHeaders()
    {
        $email = new Email();
        $email->getHeaders()->add(new TagHeader('category-one'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));
        $envelope = new Envelope(new Address('alice@system.com')[new Address('bob@system.com')]);

        $transport = new SendgridApiTransport('ACCESS_KEY');
        $method = new \ReflectionMethod(SendgridApiTransport::class, 'getPayload');
        $payload = $method->invoke($transport$email$envelope);

        $this->assertArrayHasKey('categories', $payload);
        $this->assertArrayHasKey('custom_args', $payload['personalizations'][0]);

        $this->assertCount(1, $payload['categories']);
        
$mail->subject('Hello!')
            ->to(new Address('saif.gmati@symfony.com', 'Saif Eddin'))
            ->cc(new Address('jeremy@derusse.com', 'Jérémy'))
            ->from(new Address('fabpot@symfony.com', 'Fabién'))
            ->text('Hello There!')
            ->html('<b>Hello There!</b>')
            ->replyTo(new Address('replyto-1@example.com')new Address('replyto-2@example.com'))
            ->returnPath(new Address('bounces@example.com'));

        $mail->getHeaders()->addTextHeader('X-SES-CONFIGURATION-SET', 'aws-configuration-set-name');
        $mail->getHeaders()->addTextHeader('X-SES-SOURCE-ARN', 'aws-source-arn');
        $mail->getHeaders()->add(new MetadataHeader('tagName1', 'tag Value1'));
        $mail->getHeaders()->add(new MetadataHeader('tagName2', 'tag Value2'));

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

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

    public function testSendThrowsForErrorResponse()
    {
        $client = new MockHttpClient(function Dstring $method, string $url, array $options): ResponseInterface {
            $json = json_encode([
                
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesSmtpTransport;
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mime\Email;

class SesSmtpTransportTest extends TestCase
{
    public function testTagAndMetadataAndMessageStreamHeaders()
    {
        $email = new Email();
        $email->getHeaders()->add(new MetadataHeader('tagName1', 'tag Value1'));
        $email->getHeaders()->add(new MetadataHeader('tagName2', 'tag Value2'));

        $transport = new SesSmtpTransport('user', 'pass');
        $method = new \ReflectionMethod(SesSmtpTransport::class, 'addSesHeaders');
        $method->invoke($transport$email);

        $this->assertCount(1, $email->getHeaders()->toArray());
        $this->assertTrue($email->getHeaders()->has('X-SES-MESSAGE-TAGS'));
        $this->assertSame('X-SES-MESSAGE-TAGS: tagName1=tag Value1, tagName2=tag Value2', $email->getHeaders()->get('X-SES-MESSAGE-TAGS')->toString());
    }
}
$this->expectException(HttpTransportException::class);
        $this->expectExceptionMessage('Unable to send an email: i\'m a teapot (code 418).');
        $transport->send($mail);
    }

    public function testTagAndMetadataHeaders()
    {
        $email = new Email();
        $email->getHeaders()->addTextHeader('foo', 'bar');
        $email->getHeaders()->add(new TagHeader('password-reset'));
        $email->getHeaders()->add(new TagHeader('product-name'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));

        $transport = new MailgunHttpTransport('key', 'domain');
        $method = new \ReflectionMethod(MailgunHttpTransport::class, 'addMailgunHeaders');
        $method->invoke($transport$email);

        $this->assertCount(4, $email->getHeaders()->toArray());
        $this->assertSame('foo: bar', $email->getHeaders()->get('foo')->toString());
        $tagHeaders = iterator_to_array($email->getHeaders()->all('X-Mailgun-Tag'));
        $this->assertCount(2, $tagHeaders);
        $this->assertSame('X-Mailgun-Tag: password-reset', $tagHeaders[0]->toString());
        
use Symfony\Component\Mailer\Header\TagHeader;
use Symfony\Component\Mime\Email;

class MandrillSmtpTransportTest extends TestCase
{
    public function testTagAndMetadataHeaders()
    {
        $email = new Email();
        $email->getHeaders()->addTextHeader('foo', 'bar');
        $email->getHeaders()->add(new TagHeader('password-reset,user'));
        $email->getHeaders()->add(new TagHeader('another'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));

        $transport = new MandrillSmtpTransport('user', 'password');
        $method = new \ReflectionMethod(MandrillSmtpTransport::class, 'addMandrillHeaders');
        $method->invoke($transport$email);

        $this->assertCount(3, $email->getHeaders()->toArray());
        $this->assertSame('foo: bar', $email->getHeaders()->get('FOO')->toString());
        $this->assertSame('X-MC-Tags: password-reset,user,another', $email->getHeaders()->get('X-MC-Tags')->toString());
        $this->assertSame('X-MC-Metadata: '.json_encode(['Color' => 'blue', 'Client-ID' => '12345'])$email->getHeaders()->get('X-MC-Metadata')->toString());
    }
}
$transport->send($mail);
    }

    public function testTagAndMetadataHeaders()
    {
        $json = json_encode(['foo' => 'bar']);
        $email = new Email();
        $email->getHeaders()->addTextHeader('h:X-Mailgun-Variables', $json);
        $email->getHeaders()->addTextHeader('Custom-Header', 'value');
        $email->getHeaders()->add(new TagHeader('password-reset'));
        $email->getHeaders()->add(new TagHeader('product-name'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));
        $envelope = new Envelope(new Address('alice@system.com')[new Address('bob@system.com')]);

        $transport = new MailgunApiTransport('ACCESS_KEY', 'DOMAIN');
        $method = new \ReflectionMethod(MailgunApiTransport::class, 'getPayload');
        $payload = $method->invoke($transport$email$envelope);
        $this->assertArrayHasKey('h:X-Mailgun-Variables', $payload);
        $this->assertEquals($json$payload['h:X-Mailgun-Variables']);
        $this->assertArrayHasKey('h:Custom-Header', $payload);
        $this->assertEquals('value', $payload['h:Custom-Header']);
        $this->assertArrayHasKey(0, $payload);
        
/** * @author Kevin Bond <kevinbond@gmail.com> */
class MailgunSmtpTransportTest extends TestCase
{
    public function testTagAndMetadataHeaders()
    {
        $email = new Email();
        $email->getHeaders()->addTextHeader('foo', 'bar');
        $email->getHeaders()->add(new TagHeader('password-reset'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));

        $transport = new MailgunSmtpTransport('user', 'password');
        $method = new \ReflectionMethod(MailgunSmtpTransport::class, 'addMailgunHeaders');
        $method->invoke($transport$email);

        $this->assertCount(3, $email->getHeaders()->toArray());
        $this->assertSame('foo: bar', $email->getHeaders()->get('foo')->toString());
        $this->assertSame('X-Mailgun-Tag: password-reset', $email->getHeaders()->get('X-Mailgun-Tag')->toString());
        $this->assertSame('X-Mailgun-Variables: '.json_encode(['Color' => 'blue', 'Client-ID' => '12345'])$email->getHeaders()->get('X-Mailgun-Variables')->toString());
    }
}
->text('Hello There!');

        $this->expectException(HttpTransportException::class);
        $this->expectExceptionMessage('Unable to send an email: i\'m a teapot (code 418).');
        $transport->send($mail);
    }

    public function testTagAndMetadataAndMessageStreamHeaders()
    {
        $email = new Email();
        $email->getHeaders()->add(new TagHeader('password-reset'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));
        $email->getHeaders()->add(new MessageStreamHeader('broadcasts'));
        $envelope = new Envelope(new Address('alice@system.com')[new Address('bob@system.com')]);

        $transport = new PostmarkApiTransport('ACCESS_KEY');
        $method = new \ReflectionMethod(PostmarkApiTransport::class, 'getPayload');
        $payload = $method->invoke($transport$email$envelope);

        $this->assertArrayNotHasKey('Headers', $payload);
        $this->assertArrayHasKey('Tag', $payload);
        $this->assertArrayHasKey('Metadata', $payload);
        
->text('Hello There!');

        $this->expectException(HttpTransportException::class);
        $this->expectExceptionMessage('Unable to send an email: i\'m a teapot (code 418).');
        $transport->send($mail);
    }

    public function testTagAndMetadataHeaders()
    {
        $email = new Email();
        $email->getHeaders()->add(new TagHeader('password-reset'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));
        $envelope = new Envelope(new Address('alice@system.com')[new Address('bob@system.com')]);

        $transport = new MandrillApiTransport('ACCESS_KEY');
        $method = new \ReflectionMethod(MandrillApiTransport::class, 'getPayload');
        $payload = $method->invoke($transport$email$envelope);

        $this->assertArrayHasKey('message', $payload);
        $this->assertArrayNotHasKey('headers', $payload['message']);
        $this->assertArrayHasKey('tags', $payload['message']);
        $this->assertSame(['password-reset']$payload['message']['tags']);
        
'sendinblue+api://example.com:99',
        ];
    }

    public function testCustomHeader()
    {
        $params = ['param1' => 'foo', 'param2' => 'bar'];
        $json = json_encode(['"custom_header_1' => 'custom_value_1']);

        $email = new Email();
        $email->getHeaders()
            ->add(new MetadataHeader('custom', $json))
            ->add(new TagHeader('TagInHeaders'))
            ->addTextHeader('templateId', 1)
            ->addParameterizedHeader('params', 'params', $params)
            ->addTextHeader('foo', 'bar')
        ;
        $envelope = new Envelope(new Address('alice@system.com', 'Alice')[new Address('bob@system.com', 'Bob')]);

        $transport = new SendinblueApiTransport('ACCESS_KEY');
        $method = new \ReflectionMethod(SendinblueApiTransport::class, 'getPayload');
        $payload = $method->invoke($transport$email$envelope);

        
$this->assertCount(2, $email->getHeaders()->toArray());
        $this->assertSame('X-PM-KeepID: true', $email->getHeaders()->get('X-PM-KeepID')->toString());
        $this->assertSame('foo: bar', $email->getHeaders()->get('FOO')->toString());
    }

    public function testTagAndMetadataAndMessageStreamHeaders()
    {
        $email = new Email();
        $email->getHeaders()->addTextHeader('foo', 'bar');
        $email->getHeaders()->add(new TagHeader('password-reset'));
        $email->getHeaders()->add(new MetadataHeader('Color', 'blue'));
        $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345'));
        $email->getHeaders()->add(new MessageStreamHeader('broadcasts'));

        $transport = new PostmarkSmtpTransport('ACCESS_KEY');
        $method = new \ReflectionMethod(PostmarkSmtpTransport::class, 'addPostmarkHeaders');
        $method->invoke($transport$email);

        $this->assertCount(6, $email->getHeaders()->toArray());
        $this->assertSame('foo: bar', $email->getHeaders()->get('FOO')->toString());
        $this->assertSame('X-PM-KeepID: true', $email->getHeaders()->get('X-PM-KeepID')->toString());
        $this->assertSame('X-PM-Tag: password-reset', $email->getHeaders()->get('X-PM-Tag')->toString());
        
'brevo+api://example.com:99',
        ];
    }

    public function testCustomHeader()
    {
        $params = ['param1' => 'foo', 'param2' => 'bar'];
        $json = json_encode(['"custom_header_1' => 'custom_value_1']);

        $email = new Email();
        $email->getHeaders()
            ->add(new MetadataHeader('custom', $json))
            ->add(new TagHeader('TagInHeaders'))
            ->addTextHeader('templateId', 1)
            ->addParameterizedHeader('params', 'params', $params)
            ->addTextHeader('foo', 'bar');
        $envelope = new Envelope(new Address('alice@system.com', 'Alice')[new Address('bob@system.com', 'Bob')]);

        $transport = new BrevoApiTransport('ACCESS_KEY');
        $method = new \ReflectionMethod(BrevoApiTransport::class, 'getPayload');
        $payload = $method->invoke($transport$email$envelope);

        $this->assertArrayHasKey('X-Mailin-Custom', $payload['headers']);
        
Home | Imprint | This part of the site doesn't use cookies.