DEV Community

Cover image for Sending Email in Node.js
Dexter
Dexter

Posted on • Updated on • Originally published at blog.lamtell.com

Sending Email in Node.js

Superface.ai is a language and a protocol for abstracting integrations to application use-cases. It allows use-case discovery and distribution of integration code at runtime.

Implementing API Integration becomes easy with Superface.ai because you just need to learn it and you can implement more just 40 use-cases without having to learn how to implement all of them separately.

Now I'll show you how you can send email with node.js using Superface.ai. First create a node.js package.json file using

npm init -y
Enter fullscreen mode Exit fullscreen mode

Then you have to install the superface sdk you need to install this to use superface

npm install --save @superfaceai/one-sdk
Enter fullscreen mode Exit fullscreen mode

Image description

Then choose your use-case we are going to use Send Email in the Communication section. Install communication/send-email for this use-case. Depending upon the what you want you can install different packages like for face detection computer-vision/face-detection etc.

npx @superfaceai/cli install communication/send-email
Enter fullscreen mode Exit fullscreen mode

Image description

Now you have configure the provider you want to use I am going with sendgrid. First create your on sendgrid account get your api key and verify Single Sender Verification

npx @superfaceai/cli configure sendgrid -p communication/send-email
//use set for Win 10
export SENDGRID_TOKEN=<your-value-from-sendgrid>
Enter fullscreen mode Exit fullscreen mode

I am using https://emailfake.com/ to get some temporary email. Some alternative options

https://10minutemail.com/

https://mytemp.email/

After setting up your provider copy paste the code from the example

const { SuperfaceClient } = require('@superfaceai/one-sdk');

        const sdk = new SuperfaceClient();

        async function run() {
          // Load the installed profile
          const profile = await sdk.getProfile('communication/send-email');

          // Use the profile
          const result = await profile
            .getUseCase('SendEmail')
            .perform({
              from: 'cedesdxesxd@24mail.top',
              to: 'cedesdxesxd@omdiaco.com',
              subject: 'Your order has been shipped!',
              text: 'Hello Cedes, your recent order on Our Shop has been shipped.',
            });

            try {
                const data = result.unwrap();
                console.log(data)
              } catch (error) {
                console.error(error)
              }
        }

run();
Enter fullscreen mode Exit fullscreen mode

Everything is done now just run your code as we can see email is received

Image description

Now you can implement API integration for more than 40 use-cases learning just Superface.ai

To learn how to send email in Node.js

Original Blog - https://blog.lamtell.com/blog/superfaceai-new-era-for-api

Github Code - https://github.com/cigar-galaxy82/Email-Node.js

Top comments (0)