getSender example

$salesChannel = $this->salesChannelRepository->search($criteria$context)->get($salesChannelId);

            if ($salesChannel === null) {
                throw new SalesChannelNotFoundException($salesChannelId);
            }

            $templateData['salesChannel'] = $salesChannel;
        } elseif ($this->templateDataContainsSalesChannel($templateData)) {
            $salesChannel = $templateData['salesChannel'];
        }

        $senderEmail = $data['senderMail'] ?? $this->getSender($data$salesChannelId);

        if ($senderEmail === null) {
            $event = new MailErrorEvent(
                $context,
                Level::Error,
                null,
                'senderMail not configured for salesChannel: ' . $salesChannelId . '. Please check system_config \'core.basicInformation.email\'',
                null,
                $templateData
            );

            

        $this->getReceiver()->ack($envelope);
    }

    public function reject(Envelope $envelope): void
    {
        $this->getReceiver()->reject($envelope);
    }

    public function send(Envelope $envelope): Envelope
    {
        return $this->getSender()->send($envelope);
    }

    public function setup(): void
    {
        $this->connection->setup();
    }

    public function getMessageCount(): int
    {
        return $this->getReceiver()->getMessageCount();
    }

    
$stringified = ['email' => $address->getAddress()];

            if ($address->getName()) {
                $stringified['name'] = $address->getName();
            }

            return $stringified;
        };

        $payload = [
            'personalizations' => [],
            'from' => $addressStringifier($envelope->getSender()),
            'content' => $this->getContent($email),
        ];

        if ($email->getAttachments()) {
            $payload['attachments'] = $this->getAttachments($email);
        }

        $personalization = [
            'to' => array_map($addressStringifier$this->getRecipients($email$envelope)),
            'subject' => $email->getSubject(),
        ];
        
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Header\Headers;
use Symfony\Component\Mime\Header\PathHeader;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\RawMessage;

class EnvelopeTest extends TestCase
{
    public function testConstructorWithAddressSender()
    {
        $e = new Envelope(new Address('fabien@symfony.com')[new Address('thomas@symfony.com')]);
        $this->assertEquals(new Address('fabien@symfony.com')$e->getSender());
    }

    public function testConstructorWithAddressSenderAndNonAsciiCharactersInLocalPartOfAddress()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Invalid sender "fabièn@symfony.com": non-ASCII characters not supported in local-part of email.');
        new Envelope(new Address('fabièn@symfony.com')[new Address('thomas@symfony.com')]);
    }

    public function testConstructorWithNamedAddressSender()
    {
        
$formattedAddresses = [];
        foreach ($addresses as $address) {
            $formattedAddresses[] = $this->formatAddress($address);
        }

        return $formattedAddresses;
    }

    private function getPayload(Email $email, Envelope $envelope): array
    {
        $payload = [
            'sender' => $this->formatAddress($envelope->getSender()),
            'to' => $this->formatAddresses($this->getRecipients($email$envelope)),
            'subject' => $email->getSubject(),
        ];
        if ($attachements = $this->prepareAttachments($email)) {
            $payload['attachment'] = $attachements;
        }
        if ($emails = $email->getReplyTo()) {
            $payload['replyTo'] = current($this->formatAddresses($emails));
        }
        if ($emails = $email->getCc()) {
            $payload['cc'] = $this->formatAddresses($emails);
        }
throw new HttpTransportException('Unable to send an email: '.$result['message'].sprintf(' (code %d).', $statusCode)$response);
        }

        $sentMessage->setMessageId($result['emails'][0]['message_id']);

        return $response;
    }

    private function getPayload(Email $email, Envelope $envelope): array
    {
        $payload = [
            'from' => $this->formatAddress($envelope->getSender()),
            'to' => $this->formatAddresses($this->getRecipients($email$envelope)),
            'subject' => $email->getSubject(),
            'project_id' => $this->projectId,
        ];
        if ($emails = $email->getCc()) {
            $payload['cc'] = $this->formatAddresses($emails);
        }
        if ($emails = $email->getBcc()) {
            $payload['bcc'] = $this->formatAddresses($emails);
        }
        if ($email->getTextBody()) {
            


        if (isset($headers['x-message-id'][0])) {
            $sentMessage->setMessageId($headers['x-message-id'][0]);
        }

        return $response;
    }

    private function getPayload(Email $email, Envelope $envelope): array
    {
        $sender = $envelope->getSender();

        $payload = [
            'from' => array_filter([
                'email' => $sender->getAddress(),
                'name' => $sender->getName(),
            ]),
            'to' => $this->prepareAddresses($this->getRecipients($email$envelope)),
            'subject' => $email->getSubject(),
        ];

        if ($attachments = $this->prepareAttachments($email)) {
            
throw new HttpTransportException('Unable to send an email: '.$result['Message'].sprintf(' (code %d).', $result['ErrorCode'])$response);
        }

        $sentMessage->setMessageId($result['MessageID']);

        return $response;
    }

    private function getPayload(Email $email, Envelope $envelope): array
    {
        $payload = [
            'From' => $envelope->getSender()->toString(),
            'To' => implode(',', $this->stringifyAddresses($this->getRecipients($email$envelope))),
            'Cc' => implode(',', $this->stringifyAddresses($email->getCc())),
            'Bcc' => implode(',', $this->stringifyAddresses($email->getBcc())),
            'ReplyTo' => implode(',', $this->stringifyAddresses($email->getReplyTo())),
            'Subject' => $email->getSubject(),
            'TextBody' => $email->getTextBody(),
            'HtmlBody' => $email->getHtmlBody(),
            'Attachments' => $this->getAttachments($email),
        ];

        $headersToBypass = ['from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'sender', 'reply-to'];
        
throw new HttpTransportException('Unable to send an email: '.$response->getContent(false)$response);
        }

        $sentMessage->setMessageId($result['id']);

        return $response;
    }

    private function getPayload(Email $email, Envelope $envelope): array
    {
        $payload = [
            'from' => $envelope->getSender()->toString(),
            'to' => implode(',', $this->stringifyAddresses($this->getRecipients($email$envelope))),
            'cc' => implode(',', $this->stringifyAddresses($email->getCc())),
            'bcc' => implode(',', $this->stringifyAddresses($email->getBcc())),
            'replyto' => implode(',', $this->stringifyAddresses($email->getReplyTo())),
            'subject' => $email->getSubject(),
            'textbody' => $email->getTextBody(),
            'htmlbody' => $email->getHtmlBody(),
            'attachments' => $this->getAttachments($email),
            'tags' => [],
        ];

        

        return sprintf('mandrill+https://%s', $this->getEndpoint());
    }

    protected function doSendHttp(SentMessage $message): ResponseInterface
    {
        $envelope = $message->getEnvelope();
        $response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/api/1.0/messages/send-raw.json', [
            'json' => [
                'key' => $this->key,
                'to' => array_map(fn (Address $recipient): string => $recipient->getAddress()$envelope->getRecipients()),
                'from_email' => $envelope->getSender()->getAddress(),
                'from_name' => $envelope->getSender()->getName(),
                'raw_message' => $message->toString(),
            ],
        ]);

        try {
            $statusCode = $response->getStatusCode();
            $result = $response->toArray(false);
        } catch (DecodingExceptionInterface) {
            throw new HttpTransportException('Unable to send an email: '.$response->getContent(false).sprintf(' (code %d).', $statusCode)$response);
        } catch (TransportExceptionInterface $e) {
            

        return $this->getReceiver()->all($limit);
    }

    public function find(mixed $id): ?Envelope
    {
        return $this->getReceiver()->find($id);
    }

    public function send(Envelope $envelope): Envelope
    {
        return $this->getSender()->send($envelope);
    }

    public function setup(): void
    {
        $this->connection->setup();
    }

    /** * Adds the Table to the Schema if this transport uses this connection. * * @param \Closure $isSameDatabase */
public function testReturnPath()
    {
        $e = new Email();
        $e->returnPath('fabien@symfony.com');
        $this->assertEquals(new Address('fabien@symfony.com')$e->getReturnPath());
    }

    public function testSender()
    {
        $e = new Email();
        $e->sender('fabien@symfony.com');
        $this->assertEquals(new Address('fabien@symfony.com')$e->getSender());

        $e->sender($fabien = new Address('fabien@symfony.com'));
        $this->assertSame($fabien$e->getSender());
    }

    public function testFrom()
    {
        $e = new Email();
        $helene = new Address('helene@symfony.com');
        $thomas = new Address('thomas@symfony.com', 'Thomas');
        $caramel = new Address('caramel@symfony.com');

        
throw new HttpTransportException($errorMessage$response);
        }

        $sentMessage->setMessageId($result['id']);

        return $response;
    }

    private function getPayload(Email $email, Envelope $envelope): array
    {
        $payload = [
            'from' => $envelope->getSender()->toString(),
            'to' => implode(',', $this->stringifyAddresses($this->getRecipients($email$envelope))),
            'cc' => implode(',', $this->stringifyAddresses($email->getCc())),
            'bcc' => implode(',', $this->stringifyAddresses($email->getBcc())),
            'replyto' => implode(',', $this->stringifyAddresses($email->getReplyTo())),
            'subject' => $email->getSubject(),
            'textbody' => $email->getTextBody(),
            'htmlbody' => $email->getHtmlBody(),
            'attachments' => $this->getAttachments($email),
            'tags' => [],
        ];

        
$this->connection->beginTransaction();

        try {
            $contacts = $this->loadContacts();

            foreach ($this->entries as $entry) {
                $this->connection->insert('s_mail_log', [
                    'type_id' => $entry->getType() ? $entry->getType()->getId() : null,
                    'order_id' => $entry->getOrder() ? $entry->getOrder()->getId() : null,
                    'shop_id' => $entry->getShop() ? $entry->getShop()->getId() : null,
                    'subject' => $entry->getSubject(),
                    'sender' => (string) $entry->getSender(),
                    'sent_at' => $entry->getSentAt()->format('Y-m-d H:i:s'),
                    'content_html' => $entry->getContentHtml(),
                    'content_text' => $entry->getContentText(),
                ]);
                $mailLogId = (int) $this->connection->lastInsertId();

                foreach ($entry->getDocuments() as $document) {
                    $this->connection->insert('s_mail_log_document', [
                        'log_id' => $mailLogId,
                        'document_id' => $document->getId(),
                    ]);
                }
return ($this->host ?: self::HOST).($this->port ? ':'.$this->port : '');
    }

    private function getPayload(Email $email, Envelope $envelope): array
    {
        $payload = [
            'key' => $this->key,
            'message' => [
                'html' => $email->getHtmlBody(),
                'text' => $email->getTextBody(),
                'subject' => $email->getSubject(),
                'from_email' => $envelope->getSender()->getAddress(),
                'to' => $this->getRecipientsPayload($email$envelope),
            ],
        ];

        if ('' !== $envelope->getSender()->getName()) {
            $payload['message']['from_name'] = $envelope->getSender()->getName();
        }

        foreach ($email->getAttachments() as $attachment) {
            $headers = $attachment->getPreparedHeaders();
            $disposition = $headers->getHeaderBody('Content-Disposition');

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