addAttachmentUrl example

->setMailAttachmentsConfig($additionalData['attachmentsConfig'] ?? null);

        foreach ($contents as $contentType => $data) {
            if ($contentType === 'text/html') {
                $mail->html($data);
            } else {
                $mail->text($data);
            }
        }

        foreach ($attachments as $url) {
            $mail->addAttachmentUrl($url);
        }

        if (isset($binAttachments)) {
            foreach ($binAttachments as $binAttachment) {
                $mail->attach(
                    $binAttachment['content'],
                    $binAttachment['fileName'],
                    $binAttachment['mimeType']
                );
            }
        }

        

class MailTest extends TestCase
{
    public function testMailInstance(): void
    {
        $mail = new Mail();

        static::assertInstanceOf(Email::class$mail);

        $mail->addAttachmentUrl('foobar');

        static::assertEquals(['foobar']$mail->getAttachmentUrls());

        $attachmentsConfig = new MailAttachmentsConfig(
            Context::createDefaultContext(),
            new MailTemplateEntity(),
            new MailSendSubscriberConfig(false),
            [],
            Uuid::randomHex()
        );

        
$envelope = $this->createMock(Envelope::class);

        $this->decorated->expects(static::once())->method('send')->with($mail$envelope);

        $this->decorator->send($mail$envelope);
    }

    public function testMailerTransportDecoratorWithUrlAttachments(): void
    {
        $mail = new Mail();
        $envelope = $this->createMock(Envelope::class);
        $mail->addAttachmentUrl('foo');
        $mail->addAttachmentUrl('bar');

        $this->filesystem->write('foo', 'foo');
        $this->filesystem->write('bar', 'bar');

        $this->decorated->expects(static::once())->method('send')->with($mail$envelope);

        $this->decorator->send($mail$envelope);
        $attachments = $mail->getAttachments();
        static::assertCount(2, $attachments);

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