Skip to content

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

@Thomas2500

Description

@Thomas2500

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions