Log In

SMTP2GO has a powerful API that lets you programmatically modify almost every aspect of your account. For example, you can use the API to dynamically add new SMTP users, send an email with custom-generated HTML, respond to statistics on your emails, and more.

Usually this requires setting up a server to respond to API calls from the internet, secure it, and make sure it stays online when you make the HTTP requests. It takes time and extensive DevOps knowledge to get this up and running properly.

However, it is possible to still access the power of SMTP2GO’s API to dynamically make changes to your account without a server

In this post, we’ll show you how you can do that with Zapier, an automation service. You’ll learn about the capabilities of the API, we’ll give you some examples to get you going, and we’ll show you how to set up Zapier to make the API requests using JavaScript.

 

What’s possible with the SMTP2GO API?

SMTP2GO’s API lets you modify various aspects of your account by giving you access to endpoints in six core areas.

Each core area provides at least three different HTTP endpoints that you’re able to access and make a request to. To learn more about the details of each endpoint, check out our documentation on the API here.

 

Examples of tasks that can be automated with the SMTP2GO API

In order to avoid repeating the same tasks multiple times, you can automate them with the API to save time. Here are a few examples:

1) When a new account gets added to your project management app, add it as an allowed sender in SMTP2GO.

If there are multiple people sending emails through your SMTP2GO account, then it might be useful to add them automatically to the allowed senders list when you invite them to join your project management app.

2) Automatically unsubscribe users who don’t open your emails after a certain amount of time.

If you have subscribers that aren’t opening emails anymore then it would be useful to automatically remove them after a certain amount of time to keep your list clean.

3) Send a custom email to a certain set of users when you post a new blog post.

Whenever some kind of notification comes in, like a new blog post or your website being down for example, you can send a custom HTML email with the SMTP2GO API.

4) Automatically add a new sender domain when you add a new domain to your list of websites.

This could be useful if you’re sending emails from multiple domains or if you need to dynamically add domains as new customers join your service.

5) Run extra calculations on your SMTP2GO email statistics.

If you need other apps to take your email statistics and do something with them it’s possible to get the data you need with the API.

Those are just a few quick examples. In the next section, let’s quickly review what Zapier is and how it can help you easily set up these automations.

 

What is Zapier?

Zapier is an automation service that allows you to integrate and automate a variety of different apps. You can connect two or more apps to automate repetitive tasks. For example, maybe you get a lot of email attachments in your Gmail account and you want to save them to Dropbox.

 

 

One app that Zapier offers is called Code. This one essentially lets you replace your server for small scripts and run custom JavaScript, or Python, code in response to an event that happens in another app.

We’re going to build out an example in the next section using Code by Zapier and Basecamp, a project management app, to make calls to the SMTP2GO API and create our first integration. The example we’ll build is automatically adding new allowed senders into our SMTP2GO account when a new user is added into Basecamp.

Let’s jump right straight in.

 

Generating your API Key

Before you can start making API requests to SMTP2GO you have to set up an API Key. To access them go to the Settings > API Keys section of your SMTP2GO Control Panel.

After clicking the Continue button you’ll see an Add API Key button. Here you’ll be presented with a modal where you can customize various aspects of your API Key.

 

 

You can give your API Key a description and also change the rate limit. Unless otherwise specified, each endpoint has a limit of 360 requests per hour.

Also, you’re able to enable and disable which endpoints of the API you want to access in the Permissions tab. This is extremely useful if you want to use specific API keys for specific purposes only.

 

 

After you’re done click the Save button and youll see the newly generated API key listed out. Click the Copy Full Key button next to the obfuscated API Key to copy the full key.

Now that we have an API Key ready to go let’s create our first automation.

 

Creating your first API automation with Zapier’s Code Service

The automation that we’ll create is the first item from the examples section above. When a new account gets added to your project management app, add that user as an allowed sender in SMTP2GO. We’ll go with Basecamp as the project management app of choice.

If you’re using a different project management app, you can still follow along but keep in mind the name of the triggers and variables might be different for you.

After signing up to Zapier and logging in, click on the Make a Zap! button in the top right corner.

Select Basecamp as your trigger. Each project management app is slightly different in its terminology for adding a new account, but it should be there. In Basecamp’s case it’s called New Person.

 

 

Next, select Code by Zapier as your action step following the Basecamp trigger step. In this post we’ll focus on writing JavaScript, but you can also write Python if you want.

 

 

Now comes the part where we’ll reach out to the API and make the email associated with that new Basecamp account an allowed sender in your SMTP2GO account.

 

Making an API request with JavaScript to SMTP2GO

After selecting Code by Zapier as the action step you should now see something like the following:

 

 

In the section titled Input Data you can choose data from the trigger service to convert into a variable for use in the code. In our case, we want to grab the email address from the Basecamp account so we can use it in the code.

 

 

Now that you have the email there as a variable, you can access it within the code as inputData.email. That’ll be useful when you’re making API Requests to SMTP2GO.

So how do you go about making an API request? Code by Zapier makes a JavaScript method available to you called fetch that allows you to make an API request.

I won’t go into the specifics of how this method works in terms of the syntax, but in the end the code would look something like the following to make an HTTP request.

 

const response = await fetch('https://api.smtp2go.com/v3/allowed_senders/add', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "api_key": "api-554XXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "allowed_senders": [inputData.email]
  })
});
 
const content = await response.json();
 
output = [content];

 

Breaking down the code

 

Line 1
const response = await fetch('https://api.smtp2go.com/v3/allowed_senders/add', {

 

The first parameter taken by the fetch method is the URL to make an HTTP Request to. In this case because we want to add an allowed sender we use that URL. The URL will change depending on your use case. See the documentation for the correct URL to use for your use case.

 

Line 2 – 6
method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },

 

The only request type accepted by SMTP2GO is POST and only accepts JSON-encoded data. These lines just ensure that things are being formatted correctly.

 

Line 6 – 9
body: JSON.stringify({
  "api_key": "api-554XXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "allowed_senders": [inputData.email]
})

 

These are probably the most important lines because it’s where all the data goes. Make sure that you put the API that you created in the previous section in here.

Finally, you’ll see that inputData.email variable here. That’s the variable that we stored previously from Basecamp.

We put that in here and now it will add that email as an allowed sender.

 

Testing your Zap

Zapier lets you test your Zap and gives you plenty of information regarding errors. You can see how long the function took to run, memory used, and any error codes returned from SMTP2GO. You can use this information to then go back and modify your code.

Hit Continue, test your Zap to make sure everything works with your Google Spreadsheets account, and finally name and turn on your Zap.

 

 

Completing your Zap

 

 

After successfully testing your code and integration to make sure that everything works you can complete your Zap.

After going through that example you can now see how to set up a Zap for anything that you might want to automate related to your SMTP2GO account. And you don’t need a server!

If you have any questions about this article please let us know! We’re available 24/7 via phone, live chat or email ticket support.

Get more email delivery tips

Sign up to get the latest SMTP2GO guides
and resources straight to your inbox.

Leave a Reply

Your email address will not be published. Required fields are marked *

Ready for better email delivery?

Try SMTP2GO free for as long as you like:

Try SMTP2GO Free → Paid plans available for over 1,000 emails/month.
×

Ready for better email delivery?
Try SMTP2GO free for as long as you like:

Try SMTP2GO Free See Pricing