genkgo / mail

Library to send e-mails over different transports and protocols (like SMTP and IMAP) using immutable messages and streams. Also includes SMTP server.
https://mail.readthedocs.io/
Other
402 stars 21 forks source link

Angle brackets by default in Content-ID and Message-ID headers #56

Closed sunnyphp closed 5 years ago

sunnyphp commented 5 years ago

Hello.

I would suggest using angle brackets in values of the Content-ID and Message-ID headers by default (auto addition in value).

Without angle brackets, image cannot be displayed, even if it does not contain special characters.

Example:

$logo = 'logotype.jpg';
$htmlBody = '<html><body><img src="cid:logotype"></body></html>';

$message = (new MessageBodyCollection($htmlBody))
    ->withEmbeddedImage(new EmbeddedImage(
        new StringStream(file_get_contents($logo)),
        basename($logo),
        new ContentType('image/jpeg'),
        new ContentID('logotype')
    ))
    ->createMessage()
    ->withHeader(new Subject('Привет мир'))
    ->withHeader(From::fromAddress('admin@mail.ru', 'Mail.ru'))
    ->withHeader(To::fromSingleRecipient('admin@gmail.com', 'Виталий'))
;

$transport = new PhpMailTransport(EnvelopeFactory::useExtractedHeader());

$transport->send($message);

But if we replace on that:

new ContentID('<logotype>')

It works.

Tested on CentOS (core Linux 2.6.32-042stab123.9 #1 SMP Thu Jun 29 13:01:59 MSK 2017 x86_64 GNU/Linux), PHP 7.2.8 (NTS) and Gmail.

An example of the link example/transport-smtp.php did not check, but I can assume that it is also not working in withEmbeddedImage method.

Thanks.

frederikbosch commented 5 years ago

Use ContentID::fromUrlAddress('id', 'domain.com'). Replace domain.com with the same address as your envelope domain and pick some random id for the first argument.