Open benedikt-schaber opened 1 year ago
I also have to read through some specs to see if this implementation is correct etc. Will do this evening (UTC+1).
The good:
The potentially bad:
ResolvedContent
typeresolveContent
resolveMessage
resolveContent
functionThe funny:
git rebase -i
-ing and fear at some point did not improve the commit history anymoreI allways squash merge so no "nice" history needed.
I had a quick look and it looks quite good!
I will need some time to test it and read some spec. I might add some changes on top of yours and do some renaming etc. where needed. So expect a merge in the next few days.
I had a look at the code and it looks realy good! But I don't know if we need related-attachments:
I pushed a fix to feat/attachment-content-id-fix
with that you can run:
import { SMTPClient } from "./mod.ts";
const transport = new SMTPClient({
connection: {
hostname: "sandbox.smtp.mailtrap.io",
port: 25,
tls: false,
auth: {
username: "xxx",
password: "xxx"
}
},
debug: {
log: true,
noStartTLS: true,
allowUnsecure: true
}
})
transport.send({
to: "a@a.de",
html: '<p><b>Follow us on</b></p><p><a href=""><img src="cid:logo"></a></p>',
subject: "aaa",
from: "a@a.de",
attachments: [
{
filename: "test.png",
content: Deno.readFileSync("./test/e2e/attachments/image.png"),
encoding: "binary",
contentType: "image/png",
contentID: "logo"
}
]
})
And it works like you would expect!
What is the difference?
(My point is only about the related attachments the rest of the code I want to merge soon 👍 )
I quickly tested your example code and it did not work in all clients, most notably it did not work in Thunderbird. I can look into why it did not work further if requested.
One remark to feat/attachment-content-id-fix: There is a small bug, Content-ID is now written twice in client.ts Attachments would if embedded be preferably inline in most cases I think, the user should perhaps at least be given the option.
Actual differences Assuming the issues with Thunderbird (and other clients) can be resolved, I think the only difference would be to users displaying the email as plain text or rich text. Here with multipart/related inline attachments should not display, whilst clients may display inline attachments following the message. I am not confident making these statements though whilst the behavior differs from client to client.
PS: I also noticed a missing newline in my code to be spec compliant, I will fix it later
Sorry for my inactivity on this matter, I should finally have some time for some open source work again. If you wish I could resume work on this issue. However, with nodemailer being available on deno and the following uncertain future of this repository I currently do not think that introducing these features would be beneficial. If you agree I would thus propose to close this pull request.
Hello. I feel I need to prefix this PR with a little justification: This PR has multiple parts to it and most of them should have been discussed in an Issue beforehand. But, since we needed these features fast I sadly did not have the time to do so before beginning development. I hope it can still be useful and understand that it may need reworking.
The goal of this PR was to allow users to embed images. This necessitated or at least encouraged multiple other changes.
feat/related-attachments
Implements
Content-Type: multiple/related
for mimeContent. To quote Wikipedia:Minimal Example
Result:
Implementation
Added an optional field
relatedAttachments
onContent
. Also added an optional fieldrelatedAttachments
onSendConfig
that populates therelatedAttachments
field of the html mime entry upon being resolved.Then in
SMTPClient.send
check if there are relatedAttachments and if so use theencodeRelated
encoder to first encode the mimeContent itself and then the attachments inside aContent-Type: multipart/related
wrapper.feat/encoders
Since we also need to encode
Content
andAttachment
inside the related wrapper the functions have been refactored from the send method into theencode
folder. Additionally the unique boundary calculation has also been refactored here and now usesmatchAll
instead ofreplace
.