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

Image attachments not supported in MS Outlook (MacOS Ventura) #40

Closed Quesj closed 1 year ago

Quesj commented 1 year ago

Hi,

Below my code to generate an email and add an attachment. I can open the email and view the image in Apple Mail. I however get an corrupted/damage file error when attempting to open the file in MS Outlook.

import { createMimeMessage } from "mimetext";
import fs from "fs";

export const dummyMime = () => {
  const msg = createMimeMessage();
  msg.setSender({ name: "Dummy", addr: "DummyTummy@gmail.com" });
  msg.setRecipient("TummyDummy@gmail.com");
  msg.setSubject("A dummy email to test with");
  msg.addMessage({
    contentType: "text/plain",
    data: `Hello, my name is Dummy and this is a dummy email to test the email parsed with - I enjoy typescript!`,
  });

  const dataRaw = fs.readFileSync('test.jpg', {encoding: 'base64'});
  // const testRaw = Buffer.from("this is a text!").toString('base64');

  msg.addAttachment({
    filename: "test.jpg",
    contentType: "image/jpg",
    data: `${dataRaw}`,
  });

  const rawMsg = msg.asRaw();

  fs.writeFile("testEmailWithImage.eml", rawMsg, (err) => {
    if (!err) {
      console.log("email succesfully generated");
      console.log(msg.asRaw());
    }
  });

  return msg.asRaw();
};

dummyMime();
image

test

muratgozel commented 1 year ago

Hi @Quesj I tried open our .eml file and other various kind of .eml files on Outlook. Looks like Outlook .eml viewer has a problem with showing images, while other email clients shows correctly. I can confirm that this is not relevant to this library and the .eml file you get by using this library is valid. Re-open this if you find something else related please.