muratgozel / MIMEText

RFC-2822, RFC-2045 and RFC-2049 compliant raw email message generator.
https://muratgozel.github.io/MIMEText/
MIT License
82 stars 35 forks source link

text/plain alternative part disappears when adding inline Image #67

Open knathan1987 opened 8 months ago

knathan1987 commented 8 months ago

text/plain alternative part disappears when adding inline Image

const x = createMimeMessage();
x.setSender({name: "Test", addr: "test@test.com"});
x.setRecipient("test2@test.com");
x.setSubject("This is a test");

x.addMessage({
    contentType: 'text/html',
    data: "<h1>Lorem ipsum dolor sit amet...</h1>"
});

x.addMessage({
    contentType: 'text/plain',
    data: "Lorem ipsum dolor sit amet..."
});

x.addAttachment({
    inline: true,
    filename: "test.png",
    contentType: "image/png",
    data: "dGVzdA==",
    headers: { "Content-ID": "test" }
});

x.addAttachment({
    filename: "test.pdf",
    contentType: "application/pdf",
    data: "dGVzdA=="
});

console.log(x.asRaw());

Output:

Date: Wed, 06 Mar 2024 08:25:38 +0000
From: =?utf-8?B?VGVzdA==?= <test@test.com>
To: <test2@test.com>
Message-ID: <dbbd5sr1uv@test.com>
Subject: =?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=lu9hrte8tx

--lu9hrte8tx
Content-Type: multipart/related; boundary=11ntqiz482y

--11ntqiz482y
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<h1>Lorem ipsum dolor sit amet...</h1>

--11ntqiz482y
Content-ID: <test>
Content-Type: image/png; name="test.png"
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename="test.png"

dGVzdA==
--11ntqiz482y--
--lu9hrte8tx
Content-Type: application/pdf; name="test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.pdf"

dGVzdA==
--lu9hrte8tx--

Output without "inline: true":

Date: Wed, 06 Mar 2024 08:27:31 +0000
From: =?utf-8?B?VGVzdA==?= <test@test.com>
To: <test2@test.com>
Message-ID: <h8zo6zgba98@test.com>
Subject: =?utf-8?B?VGhpcyBpcyBhIHRlc3Q=?=
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=5fll5crxif3

--5fll5crxif3
Content-Type: multipart/alternative; boundary=qqzy1z2de9f

--qqzy1z2de9f
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Lorem ipsum dolor sit amet...

--qqzy1z2de9f
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<h1>Lorem ipsum dolor sit amet...</h1>

--qqzy1z2de9f--
--5fll5crxif3
Content-ID: <test>
Content-Type: image/png; name="test.png"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.png"

dGVzdA==

--5fll5crxif3
Content-Type: application/pdf; name="test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.pdf"

dGVzdA==
--5fll5crxif3--
CanRau commented 5 months ago

Just stumbled upon this as well, also so far the inline image isn't working, data base64 encoded data won't show up in the emails source 🤔

CanRau commented 5 months ago

Created a PR #70 which should fix it 🤞🏼

Till then I personally vendored the src into my project so I can move forward 🤓