Configuring Mailgun for Your Website

Mailgun is an innovative way to send bulk mail from your application. With their simple pricing model you are given 50,000 emails for free every month. Why not take advantage of that and configure your site to send more reliably? Below is an overview on configuring Mailgun for your website.

  • Login to mycloud.rackspace.com using the same credentials used to log into your Cloud Sites control panel.
  • Click on the Mailgun link located in the ‘More’ drop down menu item.

mailgun-link

  • Your account will then sync with Mailgun and get you started.
  • Feel free to test sending mail out using the sandbox you are now provided with. Once you’ve done this, or chosen not to, click “Add Your Domain”

mailgun-sandbox

Preparing Mailgun for your website.

  • Input a domain to use. Since you are likely using email with this domain already, it’s suggested to use something like mg.mydomain.com
  • Click Add domain.
  • Next we will need to add the DNS entries that are provided

mailgun-dns

Optional:
If you will be receiving emails with Mailgun rather than your own email, 
make sure to change the MX records as described on the page. If you are 
already using another email solution, you’re done!

  • Once the records have been made, click Continue to Domain Overview

Domain Information

This screen appears similar, however, this particular screen contains the information you will be using to setup Mailgun with your domain. It also allows you to view the simple SMTP settings for your Mailgun account for when you want to use a basic SMTP form.

mailgun-domain-info

WordPress Integration

mailgun-plugin

  • Leave Use HTTP API set to “Yes”
  • Install the Mailgun For WordPress plugin
  • Login to mycloud.rackspace.com, click on more > mailgun
  • At your main Mailgun control panel, you will see your API Key and custom domains
  • In the Mailgun plugin settings,  input the API key custom domain you are using and an optional tag for tracking purposes
  • Save Changes, then Test Configuration to verify it works

Alternatively:

  • Change Use HTTP API to “No”
  • Input the SMTP credentials we received earlier
  • Save and Test configuration

Now your WordPress is officially setup to use Mailgun for system emails such as password resets, login tracking, or anything else WordPress is set to use email for.

Using Mailgun For PHP Mail

Using the SMTP settings from the previous setup steps, we can setup a 
simple PHP SMTP script such as in this article:
http://www.rackspace.com/knowledge_center/article/how-do-i-test-php-smtp-functionality

Plug in your SMTP credentials and test the page. You’re done!

Using Mailgun in ASP

Using the SMTP settings from the previous setup steps allows us to setup a
simple .NET SMTP script as follows:

using System;
using System.Windows.Forms;
using System.Net.Mail;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(“smtp.mailgun.org”);

mail.From = new 
MailAddress(“your_email_address@domain.com”);
mail.To.Add(“to_address”);
mail.Subject = “Test Mail”;
mail.Body = “This is for testing SMTP mail from .NET 
through Mailgun”;

SmtpServer.Port = 587;
SmtpServer.Credentials = new 
System.Net.NetworkCredential(“USERNAME”, “PASSWORD”);
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);
MessageBox.Show(“mail Send”);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}

Plug in your SMTP credentials and test the page. You’re done!

 

For more information on how Cloud Sites by Rackspace can help you, check us out at cloud sites.rackspace.com