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

Missing line breaks after Content-Type header when using multiple parts #412

Closed
Thomas2500 opened this issue Jan 11, 2025 · 5 comments · Fixed by #413
Closed

Missing line breaks after Content-Type header when using multiple parts #412

Thomas2500 opened this issue Jan 11, 2025 · 5 comments · Fixed by #413
Assignees
Labels
bug Something isn't working

Comments

@Thomas2500
Copy link

Description

Hello!

I was just about to implement the library, but had some big problems displaying my mails correctly in GMail and Thunderbird.
Either no content was displayed or the content was displayed with broken line breaks as well as plain text and HTML content at the same time.

After downgrading the library from version 0.6.0 to 0.5.2, everything works again.
With version 0.6.0, the headers in my email are structured as follows:
(Content-Type -> boundary seems to not finish the line correctly with a line break, containing two values)

[...]
Subject: Hi
From: "Me" <[email protected]>
To: <[email protected]>
Content-Type: multipart/alternative;
 boundary=903a0c5f0e2edf2cd7f4fd9b779f273c53520b43926c7cc96dccc269dd85--903a0c5f0e2edf2cd7f4fd9b779f273c53520b43926c7cc96dccc269dd85
Content description: plain-body
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

Dear [email protected],

Thank you for reaching out to us, even though our email address is set as "=
no-reply." We appreciate your interest and value your feedback.

While this email address isn't monitored for incoming messages, we want to =
ensure you receive the assistance you need.

[...]

Yours sincerely,
Me

--903a0c5f0e2edf2cd7f4fd9b779f273c53520b43926c7cc96dccc269dd85
Content description: html-body
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8


<!DOCTYPE html>
<html lang=3D “en”>

[...]

After reverting back to v0.5.2, the same code generates the following content which let's the email render correctly within GMail and Thunderbird:

[...]
Subject: Hi
From: "Me" <[email protected]>
To: <[email protected]>
Content-Type: multipart/alternative;
 boundary=2d161352b76febeb71163561b3724ccaf73d034d535f13794a80a1488029

--2d161352b76febeb71163561b3724ccaf73d034d535f13794a80a1488029
Content-Description: plain-body
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

Dear [email protected],

Thank you for reaching out to us, even though our email address is set as "=
no-reply." We appreciate your interest and value your feedback.

While this email address isn't monitored for incoming messages, we want to =
ensure you receive the assistance you need.

[...]

Yours sincerely,
Me

--2d161352b76febeb71163561b3724ccaf73d034d535f13794a80a1488029
Content-Description: html-body
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<html lang=3D"en">

To Reproduce

Create a new message containing a text/plain part and one text/html part.

E.g. by using the following snippet (shortened out of my code, sould be reproduceable with it):

message := mail.NewMsg()
message.SetDate()
message.SetBulk()
message.SetGenHeader("BIMI-Selector", "v=BIMI1; s=default")

// Set FROM address
if err := message.FromFormat(
os.Getenv("MAIL_FROM_NAME"),
os.Getenv("MAIL_FROM_EMAIL"),
); err != nil {
return "", err
}

// Set Envelope FROM address
if err := message.EnvelopeFrom(os.Getenv("MAIL_FROM_EMAIL")); err != nil {
return "", err
}

// Set TO address
if err := message.AddToFormat(opt.Receipient.Name, opt.Receipient.Address); err != nil {
return "", err
}

message.Subject(opt.Subject)
message.AddAlternativeString(mail.TypeTextPlain, text, mail.WithPartContentDescription("plain-body"))
message.AddAlternativeString(mail.TypeTextHTML, text, mail.WithPartContentDescription("html-body"))

// Deliver the mail via SMTP
client, err := mail.NewClient(
os.Getenv("MAIL_HOST"),
mail.WithPort(587), mail.WithTLSPortPolicy(mail.TLSMandatory),
mail.WithSMTPAuth(mail.SMTPAuthPlain),
mail.WithUsername(os.Getenv("MAIL_USERNAME")), mail.WithPassword(os.Getenv("MAIL_PASSWORD")),
mail.WithDebugLog(),
)
if err != nil {
return "", err
}
defer client.Close()

if err := client.DialAndSend(message); err != nil {
return "", err
}

Expected behaviour

Both parts of email content should be written within their individual parts with line break after ending the Content-Type header, allowing email programs to correctly parse the mail contents.

Screenshots

No response

Attempted Fixes

No response

Additional context

No response

@Thomas2500 Thomas2500 added the bug Something isn't working label Jan 11, 2025
@wneessen wneessen self-assigned this Jan 12, 2025
@wneessen
Copy link
Owner

Hi @Thomas2500,

thanks for the report and sorry for the inconveniences. I'll have a look at this right now and will release a regression-release one it's fixed.

wneessen added a commit that referenced this issue Jan 12, 2025
This fixes a regression that was introduced in the S/MIME signing code of v0.6.0 which caused the msgwriter to not add a newline between the first boundary and the multipart causing the mail to be unable to render in mail clients.
@wneessen wneessen linked a pull request Jan 12, 2025 that will close this issue
@wneessen
Copy link
Owner

This has been fixed with #413.

@wneessen
Copy link
Owner

v0.6.1 has been released with the fix included.

@Thomas2500
Copy link
Author

Just tested it and everything works fine now, tank you for the very fast fix!

@wneessen
Copy link
Owner

Thanks for the confirmation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants