Using the NodeJS wrapper for Paubox Email API

NodeJS API image
NodeJS

Using the NodeJS wrapper for Paubox Email API

Paubox has its software development kit (SDK) for several popular programming languages. In this post, we go over the NodeJS wrapper that you can use to integrate Paubox Email API into your application within minutes for secure and HIPAA compliant email.

There are three main steps involved in using the wrapper.

  1. Creating a NodeJS project
  2. Configuring the credentials
  3. Invoking the API

Read our blog to get up and running quickly with the NodeJS wrapper for Paubox Email API.

Read more

Creating a NodeJS Project for secure and HIPAA compliant email

You can create a node project using one of the two popular package managers out there. If you are using yarn, run the yarn init command. If you are using npm, then run the npm init command. Ensure that you run this inside of a folder. In this example, we are using npm.

After executing the command, you can choose several options for your project. The name of the project folder in this case is paubox-node-wrapper, and that is given as the default package name. You can press ‘Enter’ through all of this to accept the defaults or enter values of your own.

Paubox node wrapper

After the execution of the command, you can see a new file named package.json in the folder. This file houses all the dependencies and scripts required to package, build and deploy your application. Notice how the entry point is a file called index.js? This is the starting point for your application, and you must create this file. Open the paubox-node-wrapper folder in your favorite code editor and create a new file called index.js.

Now you have everything ready to install Paubox’s NodeJS wrapper. Run the following command to install the package.

NPM install

Once it finishes installing the package, you’re all set to start using Paubox’s secure email API.

Configuring the credentials

The next step is to configure the credentials. For this, you must have a Paubox account. You can sign up here. After signing up, follow this 5-minute guide to verify your domain and generate an API key. Copy the API key and keep it safe, as it is shown only once. If you forget it or lose it, you’ll need to generate a new one.

Go back to your project folder and create a file named .env. Open it in your code editor and add the following lines.

API_Key for JSNode

Paste the API key that you generated earlier in the API_KEY field and paste your username from the Paubox dashboard in the API_USERNAME field. Your username is present in the unique API endpoint for your domain. See the image below for reference. The blurred portion is your unique username.

Invoking the API

We now have the project and credentials configured. All that’s left to do is to invoke the API and send a test email. Go inside your project folder once again and paste the following code inside index.js.

Invoking the API NodeJS

The first line indicates that we are running the code in strict mode. The second line uses our .env file and sets the environment variables. We initialize one object called pbMail importing the Paubox NodeJS wrapper and another object of the emailService class. Now, prepare a message object by setting a few options. The options include the ‘from’ address, ‘to’ address, subject, text content and HTML content.

After that, create a message variable and set the options variable to the pbMail object’s message variable. Finally, invoke the sendMessage() method from the email service constant we created earlier and pass in the message variable as a parameter. We are using async arrow functions here to retrieve the response and log it or catch an error and log it. If everything went well, you should see something like this in the logs.

Send Message method Response:

Source tracking NodeJS

Configuring the options variable

The options variable used in the above example also accepts other configuration parameters. See the table below.

NodeJS options variable table

Integrate Paubox Email API into your app for secure HIPAA compliant email

If you want to build something quickly, use our GitHub repository. There are several samples that you can check out on the Paubox Email API product overview page as well. We currently have samples for the following languages: C#, Java, Python3, Python2, PHP, Rails, Node, Perl and Ruby. Seasoned developers can take a look at our Developer docs and build code from scratch.

DevOps

Send your first HIPAA compliant email in minutes.

About the author

Anne-Marie Sullivan

Read more by Anne-Marie Sullivan

Get started with
end-to-end protection

Bolster your organization's security with state-of-the-art email encryption and inbound email security.

Highest rated HIPAA compliant email solution on G2

EmailEncryption BestMeetsRequirements MeetsRequirements
SecureEmailGateway MostImplementable Total
SecureEmailGateway Leader Leader
SecureEmailGateway EasiestToUse EaseOfUse
SecureEmailGateway EasiestAdmin EaseOfAdmin
SecureEmailGateway BestUsability Total
SecureEmailGateway BestResults Total
SecureEmailGateway BestRelationship Total
EmailEncryption UsersMostLikelyToRecommend Nps
EmailEncryption MomentumLeader Leader
SecureEmailGateway BestSupport Mid Market QualityOfSupport
EmailEncryption BestMeetsRequirements MeetsRequirements
SecureEmailGateway MostImplementable Total
SecureEmailGateway Leader Leader
SecureEmailGateway EasiestToUse EaseOfUse
SecureEmailGateway EasiestAdmin EaseOfAdmin
SecureEmailGateway BestUsability Total
SecureEmailGateway BestResults Total
SecureEmailGateway BestRelationship Total
EmailEncryption UsersMostLikelyToRecommend Nps
EmailEncryption MomentumLeader Leader
SecureEmailGateway BestSupport Mid Market QualityOfSupport