Sending Email in Node.js
Tags: node, api, programming, tutorial
Published: 2022-08-01 02:10:00

[Superface.ai](https://superface.ai/catalog) 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](https://superface.ai/catalog) 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
```

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

```
npm install --save @superfaceai/one-sdk
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fgi34t34mlmo2zvfbuvt.png)

Then choose your use-case we are going to use Send Email in the Communication section. Install [communication/send-email](https://superface.ai/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](https://superface.ai/computer-vision/face-detection).

```
npx @superfaceai/cli install communication/send-email
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ng5xbs3oa7grhx1c0iy7.jpg)

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](https://docs.sendgrid.com/ui/account-and-settings/api-keys#types-of-api-keys) and [verify Single Sender Verification](https://docs.sendgrid.com/ui/sending-email/sender-verification)

```
npx @superfaceai/cli configure sendgrid -p communication/send-email
//use set for Win 10
export SENDGRID_TOKEN=<your-value-from-sendgrid>
```
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();
```
Everything is done now just run your code as we can see email is received


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/91seyupr59cdjf0qx4tn.jpg)


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 {% embed https://www.youtube.com/watch?v=5keSfHm8OGo %}

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

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