So many times, we hear the question, “Do you have a playbook of some kind that lays out the process for migrating from an on-premises installation to SparkPost”?

Why yes, yes we do. Keep reading.

First, some back story. The SparkPost Cloud service was created in 2014 out of the enormous success of the On-Premises Momentum MTA solution. Momentum sits at the core of the SparkPost Cloud, providing high-speed delivery and traffic shaping for thousands of customers on the cloud service. Because of this, Momentum receives a large portion of our engineering attention, but the results of that work are often buried in performance improvements that don’t get a great deal of press.  Momentum customers see the benefits of this work every time a new public release of Momentum is published.

This does NOT mean that SparkPost is just “Momentum in the Cloud”. SparkPost is much more than that and can have added benefits for customers who choose to migrate or use them in a hybrid approach.  In addition, we have made it very easy for PowerMTA customers to migrate or use PowerMTA with SparkPost in a hybrid configuration as well. The rest of this document will describe in detail how you can migrate your message streams from Momentum or PowerMTA to the SparkPost Cloud service. 

There are really two separate scenarios to consider when migrating to SparkPost from Momentum or PowerMTA. 

  1.  You are ready to leave the on-premises world entirely, shut down your physical data centers and no longer manage any on-premises MTA directly.  This means eliminating Momentum or PowerMTA from your deployment and sending messages directly to SparkPost for message handling.or
  2. You have reason to keep some on-premises footprint for one reason or another.  Some possibilities might be:
  • specific delivery streams that require pre-processing in Momentum
  • capacity splitting for burst or disaster recovery needs
  • supporting legacy customers in PMTA while shifting new customers to SparkPost

 …then you want to forward the other messages on to SparkPost for onward message handling.  

In either situation, you need to be aware that SparkPost will only accept SMTP messages for delivery that are injected over port 587 or 2525 and use SMTP_Auth with a specific username and password (See SMTP docs here). We also highly recommend connecting with a TLS connection, but that is not strictly required. If you are replacing your MTA layer entirely (scenario 1), then you may also want to consider using the Transmissions REST API which can accept messages over HTTPS connections. Documentation on that API is here.

Which option do I choose?

To figure out if you are in option #1 or option #2, consider these factors:

  • Do you use Momentum’s Lua scripting engine for anything more complicated than message routing?
    • Lua is a comprehensive script tool for manipulating messages in-line, but the vast majority of our users only use it to select a binding for delivery.  If that is the case, you can modify your generation code to add an ip_pool attribute to the X-MSYS-API header and have SparkPost assign the route for you. 
    • If you use Lua to do more complicated things like body filtering, Mail_From rewrites, or message cadence calculations, and it’s not feasible to move that logic into your injecting application, you may want to consider switching to the Option #2 camp.
  • Is your generation system able to send messages over port 587 using TLS and SMTP_Auth?
    • Some campaign management systems can only push mail out on port 25 in cleartext. This causes a security problem for SparkPost so you may want to consider Option #2
  • Are you using PowerMTA substitution syntax or other in-line message modification?
    • If you can move this function up into your generators or use the SparkPost Template Language, then you can still use option 1, but otherwise, you may need to think about keeping a PMTA node online for this message modification before shipping to SparkPost for delivery.
  • Do you require any inbound AV/AS scanning before injection? While this is possible in Momentum and PowerMTA, SparkPost assumes you have already performed all those checks.  You may want to consider doing that before injection.

No matter which way you go, it is sure to affect your commercial relationship.  As you can imagine, this is not our first rodeo. Be sure to loop in your Commercial Account Manager and Customer Success Manager so we can help you through the details and make sure you are getting the best value for your dollar.

For Option #1 Camp (Going “cold turkey”):

Let’s assume you are OK with option 1 and you are ready to shut down your on-premises MTAs and you have decided to continue using the SMTP injection method, not changing your message creation systems at all.  Your generation systems should create a fully formatted SMTP message, then push to Sparkpost over TLS using SMTP_AUTH where the username and password are as described on this page. Remember that the “password” is the API key you generate in your SparkPost account with the SMTP delivery option turned on.

If you are in the Option #1 camp, consider switching to the REST API right out of your generation system. In most cases, we find that customers’ processing systems are already using JSON over HTTP and have to convert to SMTP before injection. You can skip that step and send it directly to us as a JSON formatted REST payload.

If you choose to inject with the REST API, you may need to alter your content creation system a bit, but it may be worth it.  You can find out more here.

One of the biggest concerns large ESPs have with a Migration is IP Warming. Typically they have spent many years grooming their inventory of IP addresses with great care so the thought of abandoning all that work is painful. SparkPost has worked out a Bring Your Own IP (BYOIP) process that takes care of that issue. If you have at least one contiguous /24 CIDR block, SparkPost can use those existing IPs for delivery which saves you the pain of having to warm them up again. If you are able to take advantage of that option, you can skip the section here on IP warmup.

If you feel you are ready to go here, skip ahead to “Making it happen

Leveraging Option #2 (on-prem pre-processing):

If, however, you are on team Option #2, then you will want to add some configuration changes to your deployment. The least painful way to migrate some select message streams from Momentum or PMTA to SparkPost while still using SMTP injection from your generation systems is to add a special route in your config.

For Momentum:

  1. Set up a version of Momentum > 3.6.23. 
  2. Install a valid SSL Certificate and open outbound port 587 so Momentum can talk to SparkPost Configure an outbound domain so you can route a message through Momentum to SparkPost. 
  3. With the configuration below, any message hitting this configuration will be routed to smtp.sparkpostmail.com using port 587 and SMTP_Auth with the username and password defined there.
    outbound_smtp_auth { }
    Keep_Message_Dicts_In_Memory = true
    Domain "smtp.sparkpostmail.com" {
      Remote_SMTP_Port = "587"
      Outbound_SMTP_AUTH_Type = "LOGIN"
      Outbound_SMTP_AUTH_user = "SMTP_Injection"
      Outbound_SMTP_AUTH_pass = "17258redacted8bd6cd7a8redacted8c22bce"
    }
  4. Configure the bindings you want to relay through SparkPost with TLS and gateway them to the domain you defined above.

    Note:
    TLS is not strictly required but is a strong recommendation. If TLS is not possible for some reason, then IP whitelisting the API keys is also a strong recommendation.
    binding “CustomerA-Outbound” {
    
      Gateway = "smtp-demo.sparkpostelite.com"
        TLS = "required"
        TLS_Certificate = "/etc/pki/tls/certs/trymsys.net.crt"
        TLS_Key = "/etc/pki/tls/certs/trymsys.net.key"
        TLS_Ciphers = "DEFAULT"
    }

For PowerMTA:

  1. Set up a version of PowerMTA > 4.5.0
  2. Install a valid SSL Certificate and open outbound port 587 so PowerMTA can talk to SparkPost.
  3. Configure an outbound domain path so you can route a message through PowerMTA to SparkPost. With the configuration below, any message hitting this configuration will be routed to smtp.sparkpostmail.com using port 587 and SMTP_Auth with the username and password defined there.  In PowerMTA, this is also where you can set TLS. Note this is also documented more fully here: https://www.sparkpost.com/docs/integrations/power-mta/And in the PowerMTA User Guide starting at section 10.4.3 

<domain sparkpost.rollup>
   use-unencrypted-plain-auth yes
   auth-username SMTP_Injection
   auth-password YourAPIKeygoesherewhenyougenerateit
   route smtp.sparkpostmail.com:587
   use-starttls yes
   require-starttls yes
   max-smtp-out 10
</domain>

4. Configure the VMTAs you want to relay through Sparkpost with the {sparkpost} rollup config you defined above.

<virtual-mta SparkPostRelay>
    <domain *>
        queue-to {sparkpost}
    </domain>
</virtual-mta>

Once you have those configuration changes made, any messages sent to the selected “binding” or “VMTA” should be routed automatically through SparkPost for delivery.  

Making it happen

When you start down this road, don’t make the mistake of thinking this is an overnight operation.  Doing this right will take some time and care.  

  1. Setup your SparkPost account and fully test using a development subaccount so you can filter out that traffic later.  You will need to do this for either option because you will need the API key for the SMTP_Auth password either way.
  2. If you are using SMTP injection, plan to add an X-MSYS-API header to incorporate all the metadata and message attributes needed.  Any X-Headers should be re-written as metadata and you should include the ip_pool and campaign attributes as well. A sample is available here:  https://developers.sparkpost.com/api/smtp/#header-using-the-x-msys-api-custom-header 
  3. If you are NOT using BYOIP, then you should make sure you set up slightly different sending domains for use with SparkPost so that you can run both environments in parallel for as long as it is needed.  If your current sending domain is mycompany.com, maybe set up sp.mycompany.com specifically for SparkPost delivery.  This allows you to migrate slowly and carefully while not compromising either domain.
  4. Make sure you have full domain alignment and security features enabled.  In DNS, set up DKIM, SPF, DMARC, bounce and tracking domains so they all look like they belong to the same organization.
  5. Configure Automatic IP Warmup on your defined IP_Pools.  If you are using the previously mentioned BYOIP option, you can ignore the warmup step.
  6. Start with one message stream and move forward from there.  Just like IP Warmup, you don’t want to do this all at once. Redirect a few hundred messages first, then 10% of the volume, then 20% the following day and increase until you have moved all the volume over. If you are an ESP, select a customer you can work with and test the process with their feedback.  If it all works well, move on to the next one. If you run into problems, take the time to fix it and work it into the process for the next one.
  7. Automate as much as possible with APIs.  Outside of the DNS changes, the SparkPost config can be mostly automated with a few API calls.

Data Collection from SparkPost

SparkPost reports message delivery in a webhooks feed or in the message events API.  Accessing SparkPost plain text logs is just not possible. You can pull this data back to your environment with a webhooks collector or by calling the Events API periodically and consuming the data.  We recommend using webhooks and have some recommendations on doing that right.  In its most basic form, a PHP webhook collector can be deployed in a few  lines of code:

<?php
$verb = $_SERVER['REQUEST_METHOD'];
  if ($verb == "POST") {
    $jsonStr = file_get_contents("php://input");
    http_response_code(200);
    $rnum = rand(1000,9999);
    $t = date("YmdHis") . $rnum;
    $Jfile = './data/data_'.$t.'.txt';
    if (file_exists($Jfile)) {
       $fn = basename($Jfile,".txt");
      $seq = 0;
      $ftail = substr($fn,-2,1);
      if ($ftail == "-"){
        $seq = substr($fn,-1);
      }
      $seq++;
      $Jfile = basename($Jfile,".txt")."-".$seq.".txt";
    }
      $fh = fopen($Jfile, "w") or die("Unable to create file!");
      fwrite($fh, $jsonStr);
      fclose($fh);
  }
?>

While you are experimenting, you can try them out with free collectors such as http://webhook.site/. Then when you’re ready to create production-grade webhooks collector code, take a look at https://www.sparkpost.com/blog/webhooks-beyond-the-basics/

Once you have collected all the webhook data, you can read that into a data store for additional processing.  There are also ways to push Webhooks through services like StitchData and Segment.

The same information is available in the Events API if you have a need to PULL the data and cannot accept PUSH data.  Here is a sample Event API call:
GET https://api.sparkpost.com/api/v1/events/message?/

recipients=recipient@example.com&templates=my-template&events

That API is fully documented with samples here:  https://developers.sparkpost.com/api/events/#events-get-search-for-message-events

And there is a very helpful blog post here too:  

https://www.sparkpost.com/blog/sparkpost-message-events-api/ 

If you really need the event data back in a form that looks like PMTA or Momentum logging, that is possible as well if you employ some additional conditioning code. The great news is there are a few examples to steal from already.

Recap

  1. Make sure you talk to your Sales and Success Management team.  We’ve done this before and can help you through it quickly and cost-effectively.
  2. Figure out if you are in Camp #1 (able to move entirely from On-Prem) or Camp #2 (Still need some on-prem MTA).
  3. Sign up for a free test account to evaluate the integration details.
  4. Decide on SMTP or REST API injection methods.
  5. If you are using SMTP injection, figure out how to get header data and message attributes into an X-MSYS-API header.
  6. Confirm if you can use our BYOIP process.
  7. Update your DNS with new domains if necessary.
  8. Build a small sample to test your migration.  You may need to adjust your config.
  9. Ramp up the volume until all the traffic is migrated
  10. If you fit into Camp #1, you can finally shut down your on-prem MTAs after all the traffic is migrated.

It ain’t over till it’s over

We would love to help you through this process.  We’ve been there and know how hard it can be to get On-Prem MTAs into the cloud.  We encourage you to read through our journey to the cloud and let us help you get there too.  When you finally get to the place you want to be, we can help you celebrate. Here are a few additional resources that may be useful.

Getting Momentum in the Cloud

Our DevOps Journey

The SparkPost Getting Started Guide

~ Tom