I have left Microsoft and this blog is no longer under my control. All of the content should remain for some time however and any new updates can be found at http://davedev.net.
-Dave, September 2013
Recently I moved my old MSDN Blog to the new DaveDev.net url running hosted WordPress on Azure WebSites. Setting up the new blog couldn’t have been more simple (hint – Click New – Compute – WebSites – Gallery – WordPress in the Azure Dashboard) and only took about five minutes.
The stuff that actually took the longest was customizing WordPress itself (themes, plugins, etc) , pointing the new Azure Website to a cname (davedev.azurewebsites.net to davedev.net) and then making sure I was backing up the MySQL Database. One of the areas that was not obvious to me however was how to send Emails.
Usually, if you sign up for WordPress from an online hoster or WordPress.com you will have an SMTP server set up for you which enables the wp_mail() function to automatically send Email on your behalf. This is not the case when you are running WordPress on Azure but the good news is there is a free solution via the Azure Marketplace.
The intent of this post is to walk you through the steps to get started with Email (it’s a free service too) on your WordPress Azure Website instance.
WordPress offers a crazy amount of customizations so the first step you need to do is to decide how you want to enable people to contact me on my Blog. After sifting through a bunch of contact form plugins I decided on one that would allow me to add a new tab and a clean contact form.
Here is what the Contact Tab looks like now on my Blog in a typical desktop browser:
Clicking on Contact will take the blog visitor to a clean contact form where they can enter their name, email I can each them at and then their message.
Once they click send they will get a response message if their Email has been sent correctly back to me.
If you have tried adding a similar contact plugin to your Azure Websites hosted WordPress instance this is where you will first encounter problems. Any call to send wp_mail() will result in an error as the Azure instance doesn’t know what SMTP server to use. I will cover that in a bit but first let’s walk through what the generated Email will look like.
You can easily apply filters now to the incoming Blog Emails and when you hit Reply to the Email it will be sent to the Email address the Blog visitor filled out in your Contact Form.
So how did I go about creating the Contact Form and enable Emails? The first step was to install the plugin I wanted to use for Blog Feedback Emails. I chose Contact Form 7 and then activated the Form as seen below.
The Contact Form will add a new menu option in your WordPress Dashboard called Contact. Opening it up will show a new form called “Contact form 1” with some code in it.
I copied the code from the Contact Form 1 and pasted it into a new Page for my Blog called “Contact”.
This is the Contact page you now see listed in my Blog’s Tab Menu. Now that I have a Contact Form Up and running the next step was to sign up for an SMTP Service that would send Emails on my behalf.
In order for our Contact Page to send Emails we will need a SMTP Service. Luckily for us SendGrid offers just that and is part of the Azure Store.
Simply open up the Azure Dashboard, click New, select Store and then choose SendGrid from the App Services Add-ons list.
There is a completely free tier that will enable you to get (or blast out) up to 25,000 emails a month. That is more than enough for the purposes of a Feedback page on our Blog.
Like all products in the Azure Store billing is integrated with your Azure monthly Bill as is single sign on. I get complete status for the Sendgrid Service right from my Azure Dashboard and clicking on the SendGrid Name will take me to the SendGrid portal using my Azure credentials.
The only additional step needed is to verify your email address (which will be your Microsoft ID assigned to your Azure account). Once that is done be sure to copy over your SendGrid username and password right from the AppBar by clicking Connection Info.
You will also receive an Email from the Azure Store confirming your purchase of the SendGrid service using the free tier.
Now that we have a Contact Form set up, and the SendGrid SMTP Service enabled we need to update our WordPress Blog so that any calls to the wp_mail() function will be routed to our new SMTP Service.
There are a bunch of free WordPress plugins that will allow you to do this I chose to go with WP-Mail-SMTP.
This plugin will add a new Email option in the Settings menu for your WordPress Dashboard. This is where you can set up your From and Name for the Email. Make sure you select SMTP for Wordpress emails, and then enter your SendGird information as seen below. Make sure you use the smtp.sendgrid.net SMTP Host name and specify a port. I used 587 based on the SendGrid recommendations.
That’s it! You can now send a Test message to yourself using the same settings page or go back to your Contact Form and send one from there. The only remaining recommendation I would have is to turn off new comment notifications inside your WordPress Dashboard. This is enabled by default but since my WordPress Azure Website instance could not send emails before I wasn’t getting spammed. Once the SMTP Host was set up I started to get notified every time a spam comment came in and oh my there are a lot of those with WordPress.
I am happy to announce that I have two new courses published today on Lynda.com! These courses are designed to take you from the very basic concepts of Cloud Computing, installing the tools and then all the way up to creating a fully functional Cloud Application. Full source code is included along with chapter by chapter code snippets and Visual Studio solutions. I hope you enjoy watching them as much as I did creating them.
Up and Running with Azure
Windows Azure is an open and flexible cloud platform that enables developers to quickly build, deploy, and manage applications across a global network of Microsoft-managed datacenters. If you have been wondering how you can take advantage of "the cloud" and integrate it into your existing IT environment, this course is for you. David Isbitski covers everything from the basics of signing up for a free Azure account to using the free developer tools, and covers each of the six major offerings from Azure: virtual machines; website development; Mobile Services for authenticating users and storing data; the Cloud Services API development and deployment tools; Data Services, which incorporates SQL, Table, and Blob storage; and app services like Service Bus for messaging. At the end, you'll tie it all together in a 5-node cloud service that processes operations through Web and Workers roles, communicates through a Service Bus message queue, and saves data to the cloud.
Up and Running with Azure Mobile Services
In my recent post on how to Setup Email with WordPress hosted on Azure Websites I mentioned the spam problem that will occur when running WordPress. As an example here is the amount of spam I have received since moving my MSDN Blog onto WordPress in Azure Websites two months ago.
By default any new comments on your blog posts will not be visible until you have approved them. In the past this meant each morning I would go through 10+ comments that all lead to a crazy spam email address outside the United States. If you’ve been running into the same issue there is a quick an easy fix!
Log into your Azure Websites hosted WordPress dashboard, select Plugins, and then Add new. Do a Search for Captcha and you will get back a list of popular plugins like below.
After looking at the details and user Ratings I decided to go with Captcha.
Once the Plugin is installed open up your Dashboard and select the Installed Plugins Menu. Verify that the Captcha Plugin has been activated.
You can modify the settings if you only want certain Arithmetic functions for example, but I kept the defaults as is.
Save your changes and you are all set! The Captcha will appear on your Login forms, comments, and registrations.
Registered users will not be bothered by any Captcha (you can turn this off if you wish) thus making it seamless for your blog commenters and restrictive for Spammers.
Since I installed the Captcha plugin a few days ago I have not received a single spam comment on my Blog. I highly recommend installing a similar plugin if you are running WordPress hosted on Azure Websites.