novuhq / novu

Open-Source Notification Platform. Embeddable Notification Center, E-mail, Push and Slack Integrations.
https://novu.co
Other
33.7k stars 3.46k forks source link

🐛 Bug Report: Missing additional fields in Custom SMTP provider #5689

Open frisket opened 4 weeks ago

frisket commented 4 weeks ago

📜 Description

I have a need to set some of the more advanced properties when sending emails using the Custom SMTP provider (nodemailer).

In particular, I need to add custom headers and also to control the envelope sender/from address to ensure proper bounce/reply-to handling.

For example, I need to be able to do this (sample event trigger payload):

{
   "name": "email-workflow",
    "to": {
         "subscriberId": "1234",
         "firstName": "User",
         "lastName": "One",
         "email": "user1@example.com"
    },
   "payload": {
       "email_body": "<b>This is the body of the email</b>",
       "email_subject": "This is a test"
    },
    "overrides": {
       "email": {
         "headers": {    <---- NEW
            "X-Custom-Header": "123456789"
         },
         "envelope": {  <--- NEW
               "from": "bounces+user1=example.com@mycorp.com
         },
         "senderName": "Sender User",
         "replyTo": "director1@example.com",  
         "html": "<h1>This should be the HTML part of the email</h1>",
         "text": "This should be in plain text in the email",
         "layoutIdentifier": "empty"
     }
  }
}

Looking through the code (packages/providers/src/lib/nodemailer/nodemailer.provider.ts) , it appears that this is already partially handled as the IEmailOptions interface has support for replyTo and headers. It just needs to be passed through to the nodemailer in the Custom STMP provider.

It appears that the headers are already handled in other providers, eg: sendgrid, so it should be a simple copy/paste from there, I think, like:

private createMailData(options: IEmailOptions): SendMailOptions {
    const sendMailOptions: SendMailOptions = {
....
      to: options.to,
      subject: options.subject,
      headers: options.headers    <-- new
      envelope: options.envelope <-- new
    };

    if (options.replyTo) {
      sendMailOptions.replyTo = options.replyTo;
    }

    return sendMailOptions;
  }

Adding support for the envelope options would require extending IEmailOptions with additional fields, similar to the header using something like envelope?: Record<string, string>;.

nodemailer supports envelope options here: https://nodemailer.com/message/#routing-options and https://nodemailer.com/smtp/envelope/

👟 Reproduction steps

N/A

👍 Expected behavior

Custom fields/headers should be passed through to the SMTP server

👎 Actual Behavior with Screenshots

Desired fields/headers are not passed through to the mail server

Novu version

0.24.0 (docker)

npm version

No response

node version

No response

📃 Provide any additional context for the Bug.

Seems a similar request was made here: https://github.com/novuhq/novu/issues/1949

👀 Have you spent some time to check if this bug has been raised before?

🏢 Have you read the Contributing Guidelines?

Are you willing to submit PR?

Yes I am willing to submit a PR!

linear[bot] commented 4 weeks ago

NV-3856 🐛 Bug Report: Missing additional fields in Custom SMTP provider