Sendgrid Single Sender error message (using Node.js)

Has anyone ever come across this error when trying to use send grid just as a Single Sender not when smpt is set up with send grid? I didn’t wanna go through the worry of setting up smtp on domain as yet. I believe I might be missing something so I am calling on the community for help. Or, how did any of you manage to implement Sendgrid via middleware?

Here is the error message

{“status”:“500”,“code”:“MODULE_NOT_FOUND”,“message”:“Cannot find module ‘@sendgrid/mail’\nRequire stack:\n- /opt/node_app/extensions/server_connect/modules/mail.js\n- /opt/node_app/lib/core/app.js\n- /opt/node_app/lib/core/middleware.js\n- /opt/node_app/lib/setup/routes.js\n- /opt/node_app/lib/server.js\n- /opt/node_app/index.js”,“stack”:“Error: Cannot find module ‘@sendgrid/mail’\nRequire stack:\n- /opt/node_app/extensions/server_connect/modules/mail.js\n- /opt/node_app/lib/core/app.js\n- /opt/node_app/lib/core/middleware.js\n- /opt/node_app/lib/setup/routes.js\n- /opt/node_app/lib/server.js\n- /opt/node_app/index.js\n at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)\n at Function.Module._load (internal/modules/cjs/loader.js:667:27)\n at Module.require (internal/modules/cjs/loader.js:887:19)\n at require (internal/modules/cjs/helpers.js:74:18)\n at Object. (/opt/node_app/extensions/server_connect/modules/mail.js:2:18)\n at Module._compile (internal/modules/cjs/loader.js:999:30)\n at Object.Module._extensions…js (internal/modules/cjs/loader.js:1027:10)\n at Module.load (internal/modules/cjs/loader.js:863:32)\n at Function.Module._load (internal/modules/cjs/loader.js:708:14)\n at Module.require (internal/modules/cjs/loader.js:887:19)”}

Try forcing the installation of node modules…

Screen Shot 2021-12-13 at 4.06.35 PM

Thanks @mebeingken I’ll try that now.

So here is what my setup look like
Mailer setup image


API image

still getting that error message. Thanks

The error is that it is missing the @sendgrid/mail package, it is not a package that we use default in Server Connect. Did you add some custom code that is requiring this package? If you want to use the sendgrid npm package then you have to install it with npm i @sendgrid/mail.

Thanks for your reply @patrick. I did install the Sendgrid package and try to use the Wappler Mailer setup after and still got the same error message. But the thing is I struggle a lot when it comes to implementing middleware in Wappler I hardly know how to do it or get it right. I was trying to set up this middleware per Sendgrid as a custom module in Wappler but I know I was going to struggle a lot so this is I am reaching out to see if anyone can give a helping hand by walking me though that process of creating a custom module from it or something.

Here is the middleware code from the image

echo "export SENDGRID_API_KEY='YOUR_API_KEY'" > sendgrid.env
echo "sendgrid.env" >> .gitignore
source ./sendgrid.env

npm install --save @sendgrid/mail

// using Twilio SendGrid's v3 Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
javascript
const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
const msg = {
  to: 'test@example.com', // Change to your recipient
  from: 'test@example.com', // Change to your verified sender
  subject: 'Sending with SendGrid is Fun',
  text: 'and easy to do anywhere, even with Node.js',
  html: '<strong>and easy to do anywhere, even with Node.js</strong>',
}
sgMail
  .send(msg)
  .then(() => {
    console.log('Email sent')
  })
  .catch((error) => {
    console.error(error)
  })

The Wappler Mailer doesn’t use the sendgrid package. What exactly are you trying to do, do you want to use the sendgrid package to write your own custom module or do you just want to use the smtp protocol?

You can’t do both, currently you custom module is probably giving the error. Remove your custom code and try it with just the Wappler mailer first. If you really need the sendgrid package and a cusom module then we can have a look on how to implement their code.

So, I haven’t wrote the any custom code or try to write my own custom module yet. I just npm the sendgrid package when first saw error message saying its missing, then I delete the Wappler Mailer I have created restarted Wappler and try to use the Wappler Mailer again and I got the same error. Now, Ideally I would like a to figure out how to implement this

per Sendgrid instruction

…And I am not sure whats the best way to go about it, if that’s entails creating a custom module or doing it middleware which are two things I struggle to do in Wappler and always need help with.

Maybe just explain what exactly are you trying to achieve?

I want to use sendgrid to send a email after someone register.

So why not use their SMTP with the mailer component in Wappler to do so?

Because I would like to use the Single Sender Verification way instead of the smtp setup Teodor

I just registered an account on sendgrid, verified a single sender, setup a mailer in Wappler:

Setup a send mail step in the server action:

Email received in my gmail inbox …

So, you can use your single sender with the smtp relay as explained in their docs.

Really a straightforward process. You don’t need to install any sendgrid node modules or whatever.
Probably you messed something with installing these packages or trying to create custom modules - it just works the way explained above and it’s the first time i am using sendgrid.

2 Likes

Thanks so much for doing that Teodor.