Skip to content

[Mailer] Invalid Mandrill transport API payload with named addresses #33993

@michaelperrin

Description

@michaelperrin

Symfony version(s) affected: 4.3.x / 4.4

Description

Sending emails with the Mandrill (MailChimp) API doesn't work when using named addresses for recipients or the for sender.

How to reproduce

use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\NamedAddress;
use Symfony\Component\Mailer\Transport;

$transport = Transport::fromDsn(sprintf('api://%s@mandrill', 'YOUR_KEY'));
$mailer = new Mailer($transport);

$email = new Email();
$email
    ->from(new NamedAddress('test@example.com', 'My Name'))
    ->subject('Subject')
    ->text('Message')
    ->to(
        new NamedAddress('recipient@example.com', 'Recipient Name')
    )
;

$mailer->send($email);

The following error will be returned:

Symfony\Component\Mailer\Exception\TransportException: Unable to send an email: Validation error: {"message":{"from_email":"The username portion of the email address is invalid (the portion before the @: My Name (code -2). in /var/www/html/wp-content/plugins/wmach/vendor/symfony/mailchimp-mailer/Http/Api/MandrillTransport.php:48

Possible Solution

The My Name <test@example.com> encoding of email addressed should not be used for Mandrill API. Specific parameters (from_name for sender, name for recipients) should be used instead (see API documentation).

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions