Skip to content

[Mailer] Embedded images and attachments are ignored for Mandrill transport API #33995

@michaelperrin

Description

@michaelperrin

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

Description

Attachments or embedded images sent with the Mandrill (MailChimp) API are currently ignored. This is because the attachments and images JSON keys are not set within the message key as mentioned in the documentation and that the name key is missing.

How to reproduce

use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;

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

$email = new Email();
$email
    ->from('test@example.com')
    ->subject('Subject')
    ->text('Message')
    ->to('recipient@example.com')
    ->embedFromPath('path/to/file.png', 'IMAGECID')
    ->attachFromPath('path/to/attachment')
    ->html('<p>Test</p><img src="cid:IMAGECID"><p>Test 2</p>')
;

$mailer->send($email);

This will generate a payload like this:

{
    "message": {
        "html": "<p>Test</p><img src=\"cid:IMAGECID\"><p>Test 2</p>",
    },
    "attachments": [
        {
            "type": "text/plain",
            "content": "ZXhhbXBsZSBmaWxl"
        }
    ],
    "images": [
        {
            "type": "image/png",
            "content": "ZXhhbXBsZSBmaWxl"
        }
    ]
}

instead of

{
    "message": {
        "html": "<p>Test</p><img src=\"cid:IMAGECID\"><p>Test 2</p>",
        "attachments": [
            {
                "type": "text/plain",
                "name": "myfile.txt",
                "content": "ZXhhbXBsZSBmaWxl"
            }
        ],
        "images": [
            {
                "type": "image/png",
                "name": "IMAGECID",
                "content": "ZXhhbXBsZSBmaWxl"
            }
        ]
    }
}

Possible Solution

  • Include the name key for each attachment or embedded image.
  • Place the attachment and images entries at the right place.

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