killmenot / nodemailer-postmark-transport

Postmark transport for Nodemailer
MIT License
32 stars 12 forks source link

Nodemailer 'stream' plugins are not being executed #38

Open TKone7 opened 3 weeks ago

TKone7 commented 3 weeks ago

Hey there, thanks very much for this package. While experimenting with the plugin feature of Nodemailer I realized that they don't get applied properly when using the postmark transport. With different (SMTP) transports it all worked as expected.

Any feedback is much appreciated.

Environment Nodejs v18.20.1 nodemailer: 6.9.15 nodemailer-postmark-transport: 6.0.0

Steps to Reproduce

import { Transform } from 'stream';
import nodemailer from 'nodemailer';
import postmarkTransport from 'nodemailer-postmark-transport';

const transport = nodemailer.createTransport(postmarkTransport({
  auth: {
    apiKey: process.env.TOKEN,
  },
}));

const transformer = new Transform({
  transform(chunk, encoding, done) {
    console.log(`doing some transformation, encoding ${encoding}`);
    this.push(chunk);
    done();
  },
});

transport.use('stream', (mail, callback) => {
  mail.message.transform(transformer);
  callback();
});

await transport.sendMail({
  from: "sender@domain.com",
  to: "recipient@domain.com",
  subject: "Subject",
  text: 'Testing',
});

Expected Result To see doing some transformation, encoding buffer in the logs.

Actual Result Log statement does not appear.

killmenot commented 1 week ago

@TKone7 Hi, thanks for the reporting this issue. It seems almost all in-built nodemailer's transports use sending raw data via streams. For example, ses transport: here and here

Have no idea atm how to fix it quickly, need to think about it

TKone7 commented 4 days ago

Oh I see. Maybe some context what I was trying to achieve helps: I am trying to send encrypted emails using the OpenPGP plugin for Nodemailer. But I see that the plugin reorganizes the entire email structure, changing content type headers to multipart/encrypted and adding special body elements.

After inspecting the Postmark API I realized that the only fields one can set are textBody and htmlBody. So it seems that with such an API you will never be able to construct such a "non-standard" email.

I reached out to Postmark's support to ask for input.