notifme / notifme-sdk

A Node.js library to send all kinds of transactional notifications.

Home Page:https://notifme.github.io/www/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to add different `from` Email for different providers?

sudhirkenguva opened this issue · comments

Hi,
I'm trying to have multiple providers, and trying to give different from emails for each of them.

here is what i'm trying:

                {
                    type: "smtp",
                    pool: true,
                    host: config.SMTP.HOST,
                    port: 465,
                    secure: true, // use TLS
                    auth: {
                        user: config.SMTP.USER,
                        pass: config.SMTP.PASSWORD
                    }
                },
                {
                    type: "sendgrid",
                    apiKey: config.SENDGRID
                }
            ]

can i pass from field in each provider here in above segment?
right now i'm passing it inside

  notifmeSdk
            .send({
                ...payload
            })

but in this way, i'm only able to send email with single provider, as for me every email provider is having different from emails.

Hi @Sudhir-Kumar-K you can try something along the lines:

notifmeSdk.send({
  email: {
    to: 'john@example.com',
    subject: 'Hi John',
    html: '<b>Hello John! How are you?</b>',
    customize: async (providerId, request) => ({
      ...request,
      from: providerId === 'email-sendgrid-provider' ? 'fromsendgrid@example.com' : 'fromsmtp@example.com'
    })
  }
})

Thanks @BDav24!!! Its working. But I think these details are missing in documenation.

You're welcome. Yes, the documentation is lacking on this point.