Greetings,
I noticed that when I parse an email that contains an attachment, the content property is undefined (while instead, it works correctly if the email has no attachment). My code is like this (it's actually split between two files, but it gives you an idea):
const parsedEmail = parse(email)
console.log("Email's content: ", parsedEmailObject.content);
if (parsedEmailObject.content != null) {
//Extract email's body only if it actually exists
const bodyAsHTML = new TextDecoder().decode(
objectToUInt8array(parsedEmailObject.content)
);
console.log("HTML body: ", bodyAsHTML); // TODO: what if email isn't in HTML format? How do I detect this? Probably it is enough to inspect the 'contentType' parameter
const bodyAsText = extractEmailBodyFromHTML(bodyAsHTML);
console.log("Body: ", bodyAsText);
domEmail.body(bodyAsText);
} else domEmail.body(" ");
If the email doesn't have attachmments, this code correctly extracts the email's body, while if it has attachments, it fails due to parsedEmailObject.content being undefined. My questions are:
- How should I extract the email's body when the email has one or more attachments?
- How do I extract the attachments?
Thank you for your help,
GTP
Greetings,
I noticed that when I parse an email that contains an attachment, the
contentproperty isundefined(while instead, it works correctly if the email has no attachment). My code is like this (it's actually split between two files, but it gives you an idea):If the email doesn't have attachmments, this code correctly extracts the email's body, while if it has attachments, it fails due to
parsedEmailObject.contentbeing undefined. My questions are:Thank you for your help,
GTP