SparkPost (SP) is an advanced email delivery service. For a number of reasons including reputation based sending, high deliverability, scalability etc. SP is trusted by big senders like facebook, twitter, linkedin, pinterest, paypal and you name it.
While SP is suitable for most, SPE (Sparkpost Elite) is for senders who wants to run these services on dedicated boxes. SPE also comes with white gloves support.
Integrating SP with your current application is extremely easy. It’s because:
- You can start FREE :). Its free plan comes with 10000 emails per month.
- Unlike others, there is no manual activation required. You can just open account, verify your domain and start sending immediately.
- Because SP supports both SMTP and API, integrating with your app is just simple.
If you’re still not sure how to integrate SP in your Rails app, keep reading.
Step 1: Open SP account
- Visit signup page and complete the form. It’s a very tiny form which takes less a than a minute completeUpon signup, you need to verify your email address. Unless you verify your email, you can’t add sending domain that we’ll do in next step.
Step 2: Add and verify your sending domain
Before we add it, you might ask what is sending domain and why you need this for. Here is the answer from official doc.
“A sending domain is a domain that is used to indicate who an email is from via the “From:” header. Using a custom sending domain enables you to control what recipients see as the From value in their email clients. DNS records can be configured for a sending domain, which allows recipient mail servers to authenticate your messages.“
Once you’ve added the domain, you need to verify the domain by adding SPF records. You can also follow the official doc for instructions to verify domain.
Step 3: Generate API Key
SP is really simple in terms of this. If you create an API key with “Send via SMTP”, you can use this same key for SMTP authentication. So simply create an API key from Account -> API & SMTP and select Send via SMTP from API Permission.
If you’re still not sure, follow this doc for detail instruction.
Step 4: Integrate with Rails
So you’ve done all the required ground jobs. The last part is configuring Rails to use your fresh SP credentials. This part is very simple. All you need is to put the SMTP configuration, ideally, in an initializer script. You can simply copy the following gist in a file inside your Rails app’s initializer directory (config/initializers).
Be sure to replace password and from with appropriate values. Password is the API key that you’ve created with “Send via SMTP” permission in previous step.
That’s all. You application now has all the goodness of world’s best email sending platform. Start sending now! You’ve earned it to yourself :).
Definitely you can separate your development and production configuration and/or move this config to environment variables. Also, you can configure your development environment to raise mail sending exceptions. Set
config.action_mailer.raise_delivery_errors = true
[disclaimer: I work for SparkPost with awesome people :)]