HIPAA compliant email with Paubox Email API using the Java wrapper

Java logo w API icon
Java

Using the Java wrapper for HIPAA compliant email with the Paubox Email API

In the previous post, we went over the NodeJS wrapper to integrate Paubox with your application for HIPAA compliant email. Today, we’re looking at the Java wrapper. The main steps remain the same as before. 

  • Creating a Java project
  • Configuring the credentials
  • Invoking the API

Creating a Java Project

In this example, we are using Eclipse to create a Java project. Open the Eclipse IDE, click on File from the top navbar and select New → Java Project. Enter a project name and click on Next. Then click Finish.

To use the Paubox Java SDK, you must download the stable JAR and include it in the classpath. You can download the JAR from here. To include it in your classpath, right-click on the project in Eclipse and navigate to Build PathConfigure Build Path. Select the Libraries tab and click on Classpath. From the right menu, select Add External JARs. Now, navigate to the downloaded JAR and click on Apply and Close.

Java build path
01

The next step is to create the main class. This can be done by simply right clicking on the src directory and navigating to New Class. Enter a name for the class and click Finish. In this example, we are naming the class JavaWrapper.

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 must generate a new one.

Right click the project once again and navigate to New File. To use Paubox’s secure email api, you must configure the credentials inside a properties file. Name the file as config.properties and click Finish. Inside the file add these two lines and enter the values from your account. 

APIKEY: ENTER_YOUR_API_KEY_HERE
APIUSER: ENTER_YOUR_USERNAME_HERE

Paste the API key that you generated earlier in the APIKEY field and paste your username from the Paubox dashboard in the APIUSER 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.

Domain info

Invoking the API

We now have the project and credentials configured. Let’s write some code to invoke the API. The great thing with an IDE like Eclipse is that you can resolve imports very easily by just hovering over the unresolved classes. 

F398BE95 83DD 405C BD2A 1A115F8D392C
F398BE95 83DD 405C BD2A 1A115F8D392C

The main function has only two lines of code. The first line uses the ConfigurationManager class to get the properties file. This loads the API key and username. The next line invokes the SendMessage() method. Notice that we use the classname directly since the method is static. In a production scenario you must use an instance of this class and invoke the method in a non-static manner as the arguments will be computed at runtime. 

Now, let’s take a look at the SendMessage method that houses most of the logic. In the first three lines, we create objects of Message, Content and Header. In the next line, we add recipients using the setRecipients() method of the Message object. It accepts a String array. In the next three lines, we set the from address, subject and reply to address using the setFrom(), setSubject(), and setReplyTo() methods from the Header object. All three methods accept String arguments. In the next two lines, we set the header and content objects created and configured earlier to the message object. 

Lastly, we create an instance of the EmailService class and invoke the sendMessage() method passing the message object. If everything went well, you should see something similar in your logs and an email in your inbox. 

[“sourceTrackingId”:”x00x0x00-0x00-0x00-xx00-00000x0xxx00″, “data”:”Service OK”, errors=null]

02
02

Configuring the options variable

OptionDescription
message.setAllowNonTLS(true);Add this option to allow sending mails that need not be HIPAA compliant.
message.setForceSecureNotification(“true”);Add this to use 2-factor authentication. Instead of an email, the recipient receives a notification about a new message in Paubox
message.setCc(new String[] { “[email protected]” });Sets the CC field in the email. The field accepts a single argument (of type String array) containing the email addresses.
message.setBcc(new String[] { “[email protected]” })Sets the Bcc field in the email. The field accepts a single argument (of type String array) containing the email addresses.

The options variable used in the above example also accepts other configuration parameters. See the table below. To view the source code, visit this Github page.

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 messaging 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