how it works

Virtual email servers

You get your own virtual email server to send, receive, and route messages from inside your code.

def send_text_message():
      # Sending a simple text-only message:
      MailgunMessage.send_txt("me@myhost",
          "you@yourhost, him@hishost",
          "Hello!",
          "Sending message through HTTP!")
        

Sending messages

You can send messages from within your code by performing an HTTP POST to the Mailgun API or by changing a few SMTP settings.

Mailgun.init("api-key-secret")
route = Route.make_new(
        pattern = "me@myhost.com",
        destination = "http://myhost/accept_mail")
route.upsert()

Receiving messages

When you receive a message to one of your domains, Mailgun will POST the message via HTTP to a url of your choosing.

Route:
    find(where), remove(where)
    insert(), upsert()

MailgunMessage:
    send_raw(cls, sender, recipients, mime_body)
    send_txt(cls, sender, recipients, subject, text)

def upload(request):
    body_html  = request.POST.get('body-html', '')
    for key in request.FILES:
        file = request.FILES[key]
                                                    

Using the API

The Mailgun API exposes the functions needed to send, receive, and route messages programatically.

Control panel

Set up your domains, get your API key, create routes and watch stats using the control panel.

E-mail deliverability

Mailgun provides automatic SPF and DKIM to insure that your messages won't be marked as spam.

send emails

Send using variety of protocols using the Mailgun API: HTTP, HTTPS or SMTP with TLS. See the emails you've sent in live log. Get daily and monthly reports.

route emails

Following the Routes mechanism pionieered by MVC web frameworks Mailgun routes allow you to define where incoming emails go: map recipients to URLs in your web app or forward to any mailbox on the Internet.

receive emails

Mailgun accepts emails of sizes up to 20MB, transcodes them to UTF-8, parses attachments and posts them into your app via HTTP POST. Instantly.