Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set type and boundary in multipart/alternative example #254

Merged
merged 2 commits into from
Nov 17, 2023

Conversation

kynx
Copy link
Contributor

@kynx kynx commented Nov 17, 2023

Q A
Documentation yes
Bugfix no
BC Break no
New Feature no
RFC no
QA no

Description

The current example for creating multipart/alternative emails with attachments does not set the type on the multipart/alternative part correctly and - I think but do not know for sure - set the boundary properly.

The $message->toString() from current example:

Date: Fri, 17 Nov 2023 01:28:55 +0000
MIME-Version: 1.0
Content-Type: multipart/related;
 boundary="=_9d9f789a56aeae641849c009c02fa723"

This is a message in Mime Format.  If you see this, your mail reader does not support this format.

--=_9d9f789a56aeae641849c009c02fa723
Content-Type: application/octet-stream
Content-Transfer-Encoding: 8bit

This is a message in Mime Format.  If you see this, your mail reader does not support this format.

--=_4d411f45abeb9e7a0f3f37bb3d9e31a4
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

foo
--=_4d411f45abeb9e7a0f3f37bb3d9e31a4
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<h1>foo</h1>
--=_4d411f45abeb9e7a0f3f37bb3d9e31a4--
--=_9d9f789a56aeae641849c009c02fa723
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="image-file-name.jpg"

Zm9v
--=_9d9f789a56aeae641849c009c02fa723--

Note the Content-Type: application/octet-stream - this should be Content-Type: multipart/alternative.

The correct output should be something like:

Date: Fri, 17 Nov 2023 01:47:10 +0000
MIME-Version: 1.0
Content-Type: multipart/related;
 boundary="=_d571c7f5c9c8e28e0a473154b2b8f5b7"

This is a message in Mime Format.  If you see this, your mail reader does not support this format.

--=_d571c7f5c9c8e28e0a473154b2b8f5b7
Content-Type: multipart/alternative;
 boundary="=_fcf2fe73fcee5fe8fdf249c81779d2c7"
Content-Transfer-Encoding: 8bit

This is a message in Mime Format.  If you see this, your mail reader does not support this format.

--=_fcf2fe73fcee5fe8fdf249c81779d2c7
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

foo
--=_fcf2fe73fcee5fe8fdf249c81779d2c7
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<h1>foo</h1>
--=_fcf2fe73fcee5fe8fdf249c81779d2c7--
--=_d571c7f5c9c8e28e0a473154b2b8f5b7
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="image-file-name.jpg"

Zm9v
--=_d571c7f5c9c8e28e0a473154b2b8f5b7--

I happened on this while investigating Webador/SlmMail#157. The application I'm migrating to slm/mail sets the type and boundary as in this PR, and has been sending emails over SMTP successfully for yonks.

I'm not 100% sure setting the boundary is necessary. I'm not a MIME expert, but it looks suspicious to me that the first example above has the same boundary for the message as the multipart/alternative part. Someone made the effort in the application I'm working on to explicitly set it - I suspect it was for a reason 😁 Hopefully someone here will know for sure.

Signed-off-by: matt <matt@claritum.com>
Copy link
Contributor

@Slamdunk Slamdunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right indeed. Please remove the typo line and we can release this 💪

@@ -115,8 +115,11 @@ $html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
$content = new MimeMessage();
// This order is important for email clients to properly display the correct version of the content
$content->setParts([$text, $html]);
$content->setType(Mime::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A typo I guess, removal needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah. Was working late 😉

@Slamdunk Slamdunk merged commit 621d73f into laminas:2.26.x Nov 17, 2023
4 of 5 checks passed
kynx pushed a commit to kynx/SlmMail that referenced this pull request Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants