Sending Messages

There are two ways to send emails using Mailgun API:

  • You can pass the components of the messages such as To, From, Subject, HTML and text parts, attachments, etc. Mailgun will build a MIME representation of the message and send it. This is the preferred method.
  • You can also build a MIME string yourself using a MIME library for your programming language and submit it to Mailgun.

Note

You can also use good old SMTP to send messages. But you will have to specify all advanced sending options via MIME headers

POST /<domain>/messages

Sends a message by assembling it from the components. Note that you can specify most parameters multiple times, HTTP supports this out of the box. This makes sense for parameters like cc, to or attachment.

Parameter Description
from Email address for From header
to Email address of the recipient(s). Example: "Bob <bob@host.com>". You can use commas to separate multiple recipients.
cc Same as To but for Cc
bcc Same as To but for Bcc
subject Message subject
text Body of the message. (text version)
html Body of the message. (HTML version)
attachment File attachment. You can post multiple attachment values. Important: You must use multipart/form-data encoding when sending attachments.
inline Attachment with inline disposition. Can be used to send inline images (see example). You can post multiple inline values.
o:tag Tag string. See Tagging for more information.
o:campaign Id of the campaign the message belongs to. See Campaign Analytics for details.
o:dkim Enables/disables DKIM signatures on per-message basis. Pass yes or no
o:deliverytime Desired time of delivery. See Date Format.
o:testmode Enables sending in test mode. Pass yes if needed. See Sending in Test Mode
o:tracking Toggles tracking on a per-message basis, see Tracking Messages for details. Pass yes or no.
o:tracking-clicks Toggles clicks tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes, no or htmlonly.
o:tracking-opens Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes or no.
h:X-My-Header h: prefix followed by an arbitrary value allows to append a custom MIME header to the message (X-My-Header in this case). For example, h:Reply-To to specify Reply-To address.
v:my-var v: prefix followed by an arbitrary name allows to attach a custom JSON data to the message. See Attaching Data to Messages for more information.
POST /<domain>/messages.mime

Posts a message in MIME format. Note: you will need to build a MIME string yourself. Use a MIME library for your programming language to do this. Pass the resulting MIME string as message parameter.

Note

You must use multipart/form-data encoding.

Parameter Description
to Email address of the recipient(s). Example: "Bob <bob@host.com>". You can use commas to separate multiple recipients.
message MIME string of the message. Make sure to use multipart/form-data to send this as a file upload.
o:tag Tag string. See Tagging for more information.
o:campaign Id of the campaign the message belongs to. See Campaign Analytics for details.
o:deliverytime Desired time of delivery. See Date Format.
o:dkim Enables/disabled DKIM signatures on per-message basis. Pass yes or no
o:testmode Enables sending in test mode. Pass yes if needed. See Sending in Test Mode
o:tracking Toggles tracking on a per-message basis, see Tracking Messages for details. Pass yes or no.
o:tracking-clicks Toggles clicks tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes, no or htmlonly.
o:tracking-opens Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes or no.
h:X-My-Header h: prefix followed by an arbitrary value allows to append a custom MIME header to the message (X-My-Header in this case). For example, h:Reply-To to specify Reply-To address.
v:my-var v: prefix followed by an arbitrary name allows to attach a custom JSON data to the message. See Attaching Data to Messages for more information.

Examples

Warning

Some samples are using curl utility for API examples. UNIX shells require that some characters must be escaped, for example $ becomes \$.

If your API key contains unescaped characters you may receive HTTP error 401 (Unauthorized).

Sending a plain text message:

curl -s --user api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0 \
    https://api.mailgun.net/v2/samples.mailgun.org/messages \
    -F from='Excited User <me@samples.mailgun.org>' \
    -F to=serobnic@mail.ru\
    -F to=sergeyo@profista.com \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!'
public static ClientResponse SendSimpleMessage() {
       Client client = Client.create();
       client.addFilter(new HTTPBasicAuthFilter("api",
                       "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"));
       WebResource webResource =
               client.resource("https://api.mailgun.net/v2/samples.mailgun.org" +
                               "/messages");
       MultivaluedMapImpl formData = new MultivaluedMapImpl();
       formData.add("from", "Excited User <me@samples.mailgun.org>");
       formData.add("to", "sergeyo@profista.com");
       formData.add("to", "serobnic@mail.ru");
       formData.add("subject", "Hello");
       formData.add("text", "Testing some Mailgun awesomness!");
       return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).
               post(ClientResponse.class, formData);
}
function send_simple_message() {
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/samples.mailgun.org/messages');
  curl_setopt($ch, CURLOPT_POSTFIELDS, array('from' => 'Excited User <me@samples.mailgun.org>',
                                             'to' => 'obukhov.sergey.nickolayevich@yandex.ru',
                                             'subject' => 'Hello',
                                             'text' => 'Testing some Mailgun awesomness!'));

  $result = curl_exec($ch);
  curl_close($ch);

  return $result;
}
def send_simple_message():
    return requests.post(
        "https://api.mailgun.net/v2/samples.mailgun.org/messages",
        auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
        data={"from": "Excited User <me@samples.mailgun.org>",
              "to": ["sergeyo@profista.com", "serobnic@mail.ru"],
              "subject": "Hello",
              "text": "Testing some Mailgun awesomness!"})
def send_simple_message
  RestClient.post "https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0"\
  "@api.mailgun.net/v2/samples.mailgun.org/messages",
  :from => "Excited User <me@samples.mailgun.org>",
  :to => "sergeyo@profista.com, serobnic@mail.ru",
  :subject => "Hello",
  :text => "Testing some Mailgun awesomness!"
end
public static RestResponse SendSimpleMessage() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnjp29jd6fds4gc373sgvjxteol0");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages";
       request.AddParameter("from", "Excited User <me@samples.mailgun.org>");
       request.AddParameter("to", "sergeyo@profista.com");
       request.AddParameter("to", "serobnic@mail.ru");
       request.AddParameter("subject", "Hello");
       request.AddParameter("text", "Testing some Mailgun awesomness!");
       request.Method = Method.POST;
       return client.Execute(request);
}

Sample response:

{
  "message": "Queued. Thank you.",
  "id": "<20111114174239.25659.5817@samples.mailgun.org>"
}

Sending a message with HTML and text parts. This example also attaches two files to the message:

curl -s --user api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0 \
    https://api.mailgun.net/v2/samples.mailgun.org/messages \
    -F from='Excited User <me@samples.mailgun.org>' \
    -F to='obukhov.sergey.nickolayevich@yandex.ru' \
    -F cc='sergeyo@profista.com' \
    -F bcc='serobnic@mail.ru' \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!' \
    --form-string html='<html>HTML version of the body</html>' \
    -F attachment=@files/cartman.jpg \
    -F attachment=@files/cartman.png
public static ClientResponse SendComplexMessage() {
       Client client = Client.create();
       client.addFilter(new HTTPBasicAuthFilter("api",
                       "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"));
       WebResource webResource =
               client.resource("https://api.mailgun.net/v2/samples.mailgun.org/" +
                               "messages");
       FormDataMultiPart form = new FormDataMultiPart();
       form.field("from", "Excited User <me@samples.mailgun.org>");
       form.field("to", "obukhov.sergey.nickolayevich@yandex.ru");
       form.field("bcc", "sergeyo@profista.com");
       form.field("cc", "serobnic@mail.ru");
       form.field("subject", "Hello");
       form.field("text", "Testing some Mailgun awesomness!");
       String file_separator = System.getProperty("file.separator");
       File txtFile = new File("." + file_separator +
                       "files" + file_separator + "test.txt");
       form.bodyPart(new FileDataBodyPart("attachment",txtFile,
                       MediaType.TEXT_PLAIN_TYPE));
       File jpgFile = new File("." + file_separator +
                       "files" + file_separator + "test.jpg");
       form.bodyPart(new FileDataBodyPart("attachment",jpgFile,
                       MediaType.APPLICATION_OCTET_STREAM_TYPE));
       return webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).
               post(ClientResponse.class, form);
}
function send_complex_message() {
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/samples.mailgun.org/messages');
  curl_setopt($ch, CURLOPT_POSTFIELDS, array('from' => 'Excited User <me@samples.mailgun.org>',
                                             'to' => 'obukhov.sergey.nickolayevich@yandex.ru',
                                             'cc' => 'serobnic@mail.ru',
                                             'bcc' => 'sergeyo@profista.com',
                                             'subject' => 'Hello',
                                             'text' => 'Testing some Mailgun awesomness!',
                                             'html' => '<html>HTML version of the body</html>',
                                             'attachment[1]' => '@/path/to/file.txt',
                                             'attachment[2]' => '@/path/to/pic.jpg'));

  $result = curl_exec($ch);
  curl_close($ch);

  return $result;
}
def send_complex_message():
    return requests.post(
        "https://api.mailgun.net/v2/samples.mailgun.org/messages",
        auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
        files=MultiDict([("attachment", open("files/test.jpg")),
                         ("attachment", open("files/test.txt"))]),
        data={"from": "Excited User <me@samples.mailgun.org>",
              "to": "obukhov.sergey.nickolayevich@yandex.ru",
              "cc": "serobnic@mail.ru",
              "bcc": "sergeyo@profista.com",
              "subject": "Hello",
              "text": "Testing some Mailgun awesomness!",
              "html": "<html>HTML version of the body</html>"})
def send_complex_message
  data = Multimap.new
  data[:from] = "Excited User <me@samples.mailgun.org>"
  data[:to] = "obukhov.sergey.nickolayevich@yandex.ru"
  data[:cc] = "serobnic@mail.ru"
  data[:bcc] = "sergeyo@profista.com"
  data[:subject] = "Hello"
  data[:text] = "Testing some Mailgun awesomness!"
  data[:html] = "<html>HTML version of the body</html>"
  data[:attachment] = File.new(File.join("files", "test.jpg"))
  data[:attachment] = File.new(File.join("files", "test.txt"))
  RestClient.post "https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0"\
  "@api.mailgun.net/v2/samples.mailgun.org/messages", data
end
public static RestResponse SendComplexMessage() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnjp29jd6fds4gc373sgvjxteol0");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages";
       request.AddParameter("from", "Excited User <me@samples.mailgun.org>");
       request.AddParameter("to", "obukhov.sergey.nickolayevich@yandex.ru");
       request.AddParameter("cc", "serobnic@mail.ru");
       request.AddParameter("bcc", "sergeyo@profista.com");
       request.AddParameter("subject", "Hello");
       request.AddParameter("text", "Testing some Mailgun awesomness!");
       request.AddParameter("html", "<html>HTML version of the body</html>");
       request.AddFile("attachment", Path.Combine("files", "test.jpg"));
       request.AddFile("attachment", Path.Combine("files","test.txt"));
       request.Method = Method.POST;
       return client.Execute(request);
}

Sending a MIME message which you pre-build yourself using a MIME library of your choice:

curl -s --user api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0 \
    https://api.mailgun.net/v2/samples.mailgun.org/messages.mime \
    -F to='Ev <ev@mailgun.net>' \
    -F message=@files/message.mime
public static ClientResponse SendMimeMessage() {
       Client client = Client.create();
       client.addFilter(new HTTPBasicAuthFilter("api",
                       "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"));
       WebResource webResource =
               client.resource("https://api.mailgun.net/v2/samples.mailgun.org" +
                               "/messages.mime");
       FormDataMultiPart form = new FormDataMultiPart();
       form.field("to", "sergeyo@profista.com");
       String file_separator = System.getProperty("file.separator");
       File mimeFile = new File("." + file_separator + "files" +
                       file_separator + "message.mime");
       form.bodyPart(new FileDataBodyPart("message", mimeFile,
                       MediaType.APPLICATION_OCTET_STREAM_TYPE));
       return webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).
               post(ClientResponse.class, form);
}
function send_mime_message() {
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/samples.mailgun.org/messages');
  curl_setopt($ch, CURLOPT_POSTFIELDS, array('from' => 'Excited User <me@samples.mailgun.org>',
                                             'to' => 'obukhov.sergey.nickolayevich@yandex.ru',
                                             'message' => '@files/message.mime'));

  $result = curl_exec($ch);
  curl_close($ch);

  return $result;
}
def send_mime_message():
    return requests.post(
        "https://api.mailgun.net/v2/samples.mailgun.org/messages.mime",
        auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
        data={"to": "sergeyo@profista.com"},
        files={"message": open("files/message.mime")})
def send_mime_message
  RestClient.post "https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0"\
  "@api.mailgun.net/v2/samples.mailgun.org/messages.mime",
  :to => "sergeyo@profista.com",
  :message => File.new(File.join("files", "message.mime"))
end
public static RestResponse SendMimeMessage() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnjp29jd6fds4gc373sgvjxteol0");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages.mime";
       request.AddParameter("to", "sergeyo@profista.com");
       request.AddFile("message", Path.Combine("files", "message.mime"));
       request.Method = Method.POST;
       return client.Execute(request);
}

An example of how to toggle tracking on a per-message basis. Note the o:tracking option. This will disable link rewriting for this message:

curl -s --user api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0 \
    https://api.mailgun.net/v2/samples.mailgun.org/messages \
    -F from='Sender Bob <sbob@samples.mailgun.org>' \
    -F to='Sasha Klizhentas <alex@mailgun.net>' \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!' \
    -F o:tracking=False
public static ClientResponse SendMessageNoTracking() {
       Client client = new Client();
       client.addFilter(new HTTPBasicAuthFilter("api",
                       "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"));
       WebResource webResource =
               client.resource("https://api.mailgun.net/v2/samples.mailgun.org" +
                               "/messages");
       MultivaluedMapImpl formData = new MultivaluedMapImpl();
       formData.add("from", "Excited User <me@samples.mailgun.org>");
       formData.add("to", "sergeyo@profista.com");
       formData.add("to", "serobnic@mail.ru");
       formData.add("subject", "Hello");
       formData.add("text", "Testing some Mailgun awesomness!");
       formData.add("o:tracking", false);
       return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).
               post(ClientResponse.class, formData);
}
function send_message_no_tracking() {
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/samples.mailgun.org/messages');
  curl_setopt($ch, CURLOPT_POSTFIELDS, array('from' => 'Excited User <me@samples.mailgun.org>',
                                             'to' => 'obukhov.sergey.nickolayevich@yandex.ru',
                                             'subject' => 'Hello',
                                             'text' => 'Testing some Mailgun awesomness!',
                                             'o:tracking' => false));

  $result = curl_exec($ch);
  curl_close($ch);

  return $result;
}
def send_message_no_tracking():
    return requests.post(
        "https://api.mailgun.net/v2/samples.mailgun.org/messages",
        auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
        data={"from": "Excited User <me@samples.mailgun.org>",
              "to": ["sergeyo@profista.com", "serobnic@mail.ru"],
              "subject": "Hello",
              "text": "Testing some Mailgun awesomness!",
              "o:tracking": False})
def send_message_no_tracking
  RestClient.post "https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0"\
  "@api.mailgun.net/v2/samples.mailgun.org/messages",
  :from => "Excited User <me@samples.mailgun.org>",
  :to => "sergeyo@profista.com, serobnic@mail.ru",
  :subject => "Hello",
  :text => "Testing some Mailgun awesomness!",
  "o:tracking" => false
end
public static RestResponse SendMessageNoTracking() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnjp29jd6fds4gc373sgvjxteol0");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages";
       request.AddParameter("from", "Excited User <me@samples.mailgun.org>");
       request.AddParameter("to", "sergeyo@profista.com");
       request.AddParameter("to", "serobnic@mail.ru");
       request.AddParameter("subject", "Hello");
       request.AddParameter("text", "Testing some Mailgun awesomness!");
       request.AddParameter("o:tracking", false);
       request.Method = Method.POST;
       return client.Execute(request);
}

An example of how to set message delivery time using the o:deliverytime option:

curl -s --user api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0 \
    https://api.mailgun.net/v2/samples.mailgun.org/messages \
    -F from='Sender Bob <sbob@samples.mailgun.org>' \
    -F to='Sasha Klizhentas <alex@mailgun.net>' \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!' \
    -F o:deliverytime='Fri, 14 Oct 2011 23:10:10 -0000'
public static ClientResponse SendScheduledMessage() {
       Client client = new Client();
       client.addFilter(new HTTPBasicAuthFilter("api",
                       "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"));
       WebResource webResource =
               client.resource("https://api.mailgun.net/v2/samples.mailgun.org" +
                               "/messages");
       MultivaluedMapImpl formData = new MultivaluedMapImpl();
       formData.add("from", "Excited User <me@samples.mailgun.org>");
       formData.add("to", "sergeyo@profista.com");
       formData.add("subject", "Hello");
       formData.add("text", "Testing some Mailgun awesomness!");
       formData.add("o:deliverytime", "Fri, 14 Oct 2011 23:10:10 -0000");
       return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).
               post(ClientResponse.class, formData);
}
function send_scheduled_message() {
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/samples.mailgun.org/messages');
  curl_setopt($ch, CURLOPT_POSTFIELDS, array('from' => 'Excited User <me@samples.mailgun.org>',
                                             'to' => 'obukhov.sergey.nickolayevich@yandex.ru',
                                             'subject' => 'Hello',
                                             'text' => 'Testing some Mailgun awesomness!',
                                             'o:deliverytime' => 'Fri, 25 Oct 2011 23:10:10 -0000'))

  $result = curl_exec($ch);
  curl_close($ch);

  return $result;
}
def send_scheduled_message():
    return requests.post(
        "https://api.mailgun.net/v2/samples.mailgun.org/messages",
        auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
        data={"from": "Excited User <me@samples.mailgun.org>",
              "to": "sergeyo@profista.com",
              "subject": "Hello",
              "text": "Testing some Mailgun awesomness!",
              "o:deliverytime": "Fri, 25 Oct 2011 23:10:10 -0000"})
def send_scheduled_message
  RestClient.post "https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0"\
  "@api.mailgun.net/v2/samples.mailgun.org/messages",
  :from => "Excited User <me@samples.mailgun.org>",
  :to => "sergeyo@profista.com",
  :subject => "Hello",
  :text => "Testing some Mailgun awesomeness!",
  "o:deliverytime" => "Fri, 25 Oct 2011 23:10:10 -0000"
end
public static RestResponse SendScheduledMessage() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnjp29jd6fds4gc373sgvjxteol0");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages";
       request.AddParameter("from", "Excited User <me@samples.mailgun.org>");
       request.AddParameter("to", "sergeyo@profista.com");
       request.AddParameter("subject", "Hello");
       request.AddParameter("text", "Testing some Mailgun awesomness!");
       request.AddParameter("o:deliverytime", "Fri, 14 Oct 2011 23:10:10 -0000");
       request.Method = Method.POST;
       return client.Execute(request);
}

An example of how to tag a message with the o:tag option:

curl -s --user api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0 \
    https://api.mailgun.net/v2/samples.mailgun.org/messages \
    -F from='Sender Bob <sbob@samples.mailgun.org>' \
    -F to='Sasha Klizhentas <alex@mailgun.net>' \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!' \
    -F o:tag='September newsletter' \
    -F o:tag='newsletters'
public static ClientResponse SendTaggedMessage() {
       Client client = new Client();
       client.addFilter(new HTTPBasicAuthFilter("api",
                       "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"));
       WebResource webResource =
               client.resource("https://api.mailgun.net/v2/samples.mailgun.org" +
                               "/messages");
       MultivaluedMapImpl formData = new MultivaluedMapImpl();
       formData.add("from", "Excited User <me@samples.mailgun.org>");
       formData.add("to", "sergeyo@profista.com");
       formData.add("subject", "Hello");
       formData.add("text", "Testing some Mailgun awesomness!");
       formData.add("o:tag", "September newsletter");
       formData.add("o:tag", "newsletters");
       return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).
               post(ClientResponse.class, formData);
}
function send_tagged_message() {
  $ch = curl_init();

  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, 'api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
  curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v2/samples.mailgun.org/messages');
  curl_setopt($ch, CURLOPT_POSTFIELDS, array('from' => 'Excited User <me@samples.mailgun.org>',
                                             'to' => 'obukhov.sergey.nickolayevich@yandex.ru',
                                             'subject' => 'Hello',
                                             'text' => 'Testing some Mailgun awesomness!',
                                             'o:tag[1]' => 'September newsletter',
                                             'o:tag[2]' => 'newsletters'));

  $result = curl_exec($ch);
  curl_close($ch);

  return $result;
}
def send_tagged_message():
    return requests.post(
        "https://api.mailgun.net/v2/samples.mailgun.org/messages",
        auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
        data=MultiDict([("from", "Excited User <me@samples.mailgun.org>"),
                        ("to", "sergeyo@profista.com"),
                        ("subject", "Hello"),
                        ("text", "Testing some Mailgun awesomness!"),
                        ("o:tag", "September newsletter"),
                        ("o:tag", "newsletters")]))
def send_tagged_message
  data = Multimap.new
  data[:from] = "Excited User <me@samples.mailgun.org>"
  data[:to] = "sergeyo@profista.com"
  data[:subject] = "Hello"
  data[:text] = "Testing some Mailgun awesomness!"
  data["o:tag"] = "September newsletter"
  data["o:tag"] = "newsletters"
  RestClient.post "https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0"\
  "@api.mailgun.net/v2/samples.mailgun.org/messages", data
end
public static RestResponse SendTaggedMessage() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnjp29jd6fds4gc373sgvjxteol0");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/messages";
       request.AddParameter("from", "Excited User <me@samples.mailgun.org>");
       request.AddParameter("to", "sergeyo@profista.com");
       request.AddParameter("subject", "Hello");
       request.AddParameter("text", "Testing some Mailgun awesomness!");
       request.AddParameter("o:tag", "September newsletter");
       request.AddParameter("o:tag", "newsletters");
       request.Method = Method.POST;
       return client.Execute(request);
}