Sending email from an EC2-hosted Ghost blog

Our Tech Blog is born

As you may have guessed from the title, the blog you are reading right now is powered by Ghost. When I decided it was about time we started a blog so we could share some of the great stuff we do with the wider digital community, I popped a message on our Slack channel, and the concensus among the younger, cooler members of the office was Ghost is the way to go.

But why EC2?

I did have a look at Ghost Pro, which would have been the sensible option... But then where's the fun in that?! So instead I headed for the AWS Marketplace and found Bitnami's Ghost AMI, and span up an instance from it. The rest of the config was fairly straightforward, and before long we had a Tech Blog.

Everything went swimmingly until I invited someone to join as an author, and the email failed to send. Some quick checking of the documentation suggested it was fairly straightforward, and I had three options:

  • MailGun - which is a 3rd party email sending services. We don't need another one of those, and I didn't want to enter my credit card details, so I ruled that one out.
  • AWS SES - Simple Email Service is Amazon's email sending as a service offering, which I've used before. However, we didn't have it set up at Zuto and I knew it would take a few hours for their support to get us out of the sandbox, and I was keen to get moving on this.
  • Gmail - The last option is to set up a Gmail account and get going quickly.

So my plan was to create a Gmail account, get it rolling and then move to SES once we had some posts written.

Gmail Fail

After setting up an account, and entering the details into the config.js file as required:

mail: {  
    transport: 'SMTP',
    options: {
        service: 'Gmail',
        auth: {
            user: 'youremail@gmail.com',
            pass: 'yourpassword'
        }
    }
}

But still nothing! I did some digging and it turns out that AWS block all standard SMTP ports from EC2 instances (for obvious reasons), so I'd have to go straight from SES.

Ghost Documentation Fail

According to the documentation on the Ghost support site, here's how you configure it to use SES for email sending:

mail: {  
    from: 'myemail@address.com',
    transport: 'SES',
    options: {
        AWSAccessKeyID: "AWSACCESSKEY",
        AWSSecretKey: "/AWS/SECRET"
    }
}

And this will work fine as long as your SES account is in the US-EAST-1 region. I'd set our up in EU-WEST-1, and there was nothing in the documentation about changing the region. Having just waited several hours to get my sandbox removal request in EU-WEST-1 approved by AWS, I wasn't about to get through the whole process again...

GitHub to the Rescue

My next step was going to be pulling the Ghost source code down from GitHub and figuring out how to change the region setting myself. However, after searching the repo for "region", I found this issue that had been raised.

Here it was highlighted that you could change the region in config.js as follows:

mail: {  
    transport: 'SES',
    options: {
        region: 'AWSREGION',
        AWSAccessKeyID: "AWSACCESSKEY",
        AWSSecretKey: "/AWS/SECRET"
    }
}

So back onto the server, update config.js, restart Ghost, restart Apache... and I could now send an email.

Dave Mason

Head of Software Engineering. Nurturing and empowering software engineers to create innovative, disruptive software that improves the lives of those who use it.

Manchester

Subscribe to Zuto Tech Blog

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!