Mail example

$this->View()->assign(['success' => true, 'data' => $nodes]);
    }

    /** * Creates new mail */
    public function createMailAction()
    {
        $params = $this->Request()->getParams();

        $mail = new Mail();
        $params['dirty'] = 1;
        $mail->fromArray($params);

        try {
            $this->get('models')->persist($mail);
            $this->get('models')->flush();
        } catch (Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);

            return;
        }

        
public function create(
        string $subject,
        array $sender,
        array $recipients,
        array $contents,
        array $attachments,
        array $additionalData,
        ?array $binAttachments = null
    ): Email {
        $this->assertValidAddresses(array_keys($recipients));

        $mail = (new Mail())
            ->subject($subject)
            ->from(...$this->formatMailAddresses($sender))
            ->to(...$this->formatMailAddresses($recipients))
            ->setMailAttachmentsConfig($additionalData['attachmentsConfig'] ?? null);

        foreach ($contents as $contentType => $data) {
            if ($contentType === 'text/html') {
                $mail->html($data);
            } else {
                $mail->text($data);
            }
        }
use Symfony\Component\Mime\Email;

/** * @internal * * @covers \Shopware\Core\Content\Mail\Service\Mail */
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),
            [],

        $mail = $this->createMock(Email::class);
        $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();
        
Home | Imprint | This part of the site doesn't use cookies.