##

Welcome to SparkPost! This article will show how to migrate existing applications that send using SMTP from [Mandrill](https://www.mandrill.com/) to [SparkPost](https://devcenter.heroku.com/). We’ll be adding some variables to your Heroku environment, and once that’s done, your app will need to be updated to use the new variables.

**Domain Setup**

SparkPost is setup with a sandbox domain which can be used to send up to 5 messages. To send more messages, [create a sending domain](https://web.archive.org/web/2/https://support.sparkpost.com/customer/portal/articles/1933360-verify-sending-domains) via the SparkPost dashboard or the API.

In order to properly sign and authenticate messages sent through your account, there are some changes you’ll need to make up front. [Verifying your sending domain](https://web.archive.org/web/2/https://support.sparkpost.com/customer/portal/articles/1933360-verify-sending-domains) is described in detail in our Support Center. This is one of the ways we protect your domain reputation, as well as our own reputation, from being tainted by e.g. phishing.

**Installing the SparkPost add-on**

First, lets install the add-on using the heroku  CLI:

$ heroku addons:create sparkpost

-----> Adding sparkpost to your-app-42... done, v18 (free)

Next, let’s confirm that the SparkPost API key is configured, and add it to [the local environment variables](https://devcenter.heroku.com/articles/heroku-local#set-up-your-local-environment-variables):

$ heroku config:get SPARKPOST_API_KEY -s | tee -a .env

SPARKPOST_API_KEY='YSBmYWtlIGFwaSBrZXksIG1hZGUgeW91IGxvb2sh'

$ for s in PORT HOST USERNAME PASSWORD ; do heroku config:get SPARKPOST_SMTP\_$s -s | tee -a .env ; done

Credentials and other sensitive configuration values should not be committed to source-control. In Git, you can exclude the

.env

file with

echo env >> .gitignore

**Using the SparkPost config settings in your app**

Here’s an ActionMailer example adapted from the Mandrill page:

ActionMailer::Base.smtp_settings = {

    port:                 ENV\['SPARKPOST_SMTP_PORT'\],

    address:              ENV\['SPARKPOST_SMTP_HOST'\],

    user_name:            ENV\['SPARKPOST_SMTP_USERNAME'\],

    password:             ENV\['SPARKPOST_SMTP_PASSWORD'\],

    authentication:       :login,

    enable_starttls_auto: true

}

ActionMailer::Base.delivery_method = :smtp

Check out the [SparkPost add-on page](https://devcenter.heroku.com/) for more examples, and [our API docs](https://developers.sparkpost.com/api/) for examples of how we can handle generating messages for you using our [Transmission API](https://developers.sparkpost.com/api/#/reference/transmissions).

Thanks for choosing SparkPost! If you have questions, feel free to contact us on Twitter [@SparkPost](https://twitter.com/SparkPost), ask a question on [StackOverflow](http://stackoverflow.com/questions/tagged/sparkpost), or join us on [Slack](http://slack.sparkpost.com).