Customize Form for Mailchimp

I bought a HTML template that had an email subscription form and I wanted to make it work with Mailchimp.  I wanted to keep the style of the template and not use a Mailchimp styled one.

It took some work, and I didn’t find documentation to do it, so here’s what I did:

(1) I went to my email list in Mailchimp and then Form Builder (Signup forms > Form Builder)

(2) Go to the URL provided for the form

(3) On the page that the URL takes you to (with the form), view the page source

(4) Copy these pieces of code from the source into your code:

(a) where your form should post to:

<form action="" method="POST">  

    <input type="hidden" name="u" value="foo">
    <input type="hidden" name="id" value="bar">

(b) for each field that you want to capture, find the name of the field and paste it as the name into the matching fields on the form you’re updating:

<input type="email" autocapitalize="off" autocorrect="off" name="MERGE0" id="MERGE0" size="25" value="">

(c) form submission details:

<input type="hidden" name="ht" value="foobar"> <input type="hidden" name="mc_signupsource" value="hosted">

If you submit the form and it redirects you to the web form instead of subscribing you to the list, it probably means that you have a name attribute wrong on one of your fields (and when you submitted, Mailchimp didn’t know what to do with that field).

Testing Email with RSpec

I ran into two types of errors when testing if emails triggered in the code with RSpec.

The first issue was that RSpec was not correctly determining if an email was triggered.  I knew the email was getting triggered correctly, but my test was failing.  The reason was that I was putting the should matcher too late.


I was putting this after calling the method I was testing (i.e. post :create) like I do with all of my other matchers.  However, with Mailer.should_receive, it should go before the call.

The second issue I had was that I was getting the error message:

Undefined method ‘deliver’ for nil:NilClass

For this, I had to stub out the response, like so:

Mailer.should_receive(:email_name).and_return(double(“Mailer”, :deliver => true))

How to Get Free Email Hosting for Your Domain

Google Apps no longer offers free email hosting for small businesses.  No worries – Microsoft offers free hosting through it’s new and improved Outlook and it’s extremely easy to set-up.

(1) go to and sign in (sign-up for a free account if you don’t have one)

(2) add your domain

(3) open another browser window and log into your account with your domain name registrar (the website where you registered your domain (ie or Go Daddy))

(4) in your domain name registrar account, go to where your domain name is managed and look for the place where you change nameservers.  once there, add the records listed in

(5) after you confirmed the settings are in place on, add a new mailbox (ie info for

(6) test the changes by sending an email to your new account (ie and then logging in via

Using Amazon SES to Send Emails from Rails

I wanted to switch from Sendgrid to Amazon SES to send emails because of the difference in pricing.  Adding Amazon SES to your Rails app is just as simple as adding Sendgrid would be.  I was able to set it up based on one of the answers to this Stack Overflow questions.  There’s a gem for this, but I prefer not using a gem when the solution is this simple.

  1. Sign-up for your Amazon SES account
  2. In your management console for Amazon SES, click the button for “Verify a New Sender”
  3. Specify the email address you want to send your emails from
  4. Add an email to test receiving emails at (you can only send to verified email addresses until you get production access)
  5. Verify your email by clicking the confirmation link from the automated email Amazon sends you
  6. Go back to Amazon SES, and click on the left side for SMTP settings
  7. Click the button for “Create My SMTP credentials”
  8. Record the user name and password created
  9. Add this to your development and production.rb files:
config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
      :address => "",
      :user_name => "..." # Your SMTP user here.
      :password => "...", # Your SMTP password here.
      :authentication => :login,
      :enable_starttls_auto => true

You should be all set - request production access once you've tested that your app is sending the emails ok.

Welcome Email After Devise Confirmation

After getting :confirmable working for the Rails Devise gem, I wanted to create a welcome email that would tell the user that they successfully confirmed their account and welcoming them to the site.

Here are the steps I took:

  1. Create the email views and placed them in my mailer directory
  2. I use User.rb as my model, so I created an observer to watch changes to the models.  In that app/models/user_observer.rb, I put this code:

def after_save(user)
# Send Welcome Mail after confirmation
if user.confirmed_at_changed?

This watches for the change in confirmed_at, then sends my email (welcome_mail).

3.  In application.rb, added this:

config.active_record.observers = :user_observer

Mail on provides free access to their software for one agent, so I set this up.  It took me a little more time because I use Heroku (which doesn’t host mail), with Google Apps mail.  Normally you would use your DNS settings for mapping the email in  However, since my email is hosted on Google Apps, I needed to route it through them.

Ironically, there’s no documentation on this on, which is software for the help desk.  You’d think they would be better about offering help since they provide help desk software – not the case.

It took me awhile, but what worked was, in the email (channel) settings:

  • enter the email with my domain (ie
  • select IMAPS
  • enter the host as

When I tried other settings, such as or I got errors indicating that the certification did not match (ie domain name vs  When I wrote’s support they said it was an adjustment on the mail side.  This was not the case I found, after playing with it for an hour, it was just a setting change within