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
Then you have to install the superface sdk you need to install this to use superface
npm install --save @superfaceai/one-sdk
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
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>
I am using https://emailfake.com/ to get some temporary email. Some alternative options
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
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 (3)
Thanks for sharing. Really interesting. I implemented something similar, a little bit in a different way but to tackle exactly same purposes.
There is the beast: github.com/steve-lebleu/cliam
It's a clear response to heterogeneous complixity of email sending. SMTP or API provider, same interface. If you switch the way you send emails, your code doesn't care.
With this package, you just need to define your configuration:
And to shoot:
The
nodemailercore library is still used for SMTP sendings, API providers are reached through a small HTTP client.Try it ;-)
Convenient, thanks for sharing. Unfortunately the AGPL license makes it unsuitable for any closed-source project.
True, but it's not engraved in the stone. I think I'll enlarge this license in a near future.