diff --git a/appengine/.gitignore b/appengine/.gitignore
new file mode 100644
index 00000000000..453750bc157
--- /dev/null
+++ b/appengine/.gitignore
@@ -0,0 +1,44 @@
+# Copyright 2015 Google Inc. All Rights Reserved.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Google App Engine generated folder
+appengine-generated/
+
+# Java
+*.class
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+# maven
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+
+service-account.json
+
+#eclipse
+.classpath
+.settings
+.project
diff --git a/appengine/mailgun/pom.xml b/appengine/mailgun/pom.xml
new file mode 100644
index 00000000000..77dc011713a
--- /dev/null
+++ b/appengine/mailgun/pom.xml
@@ -0,0 +1,76 @@
+
+
+
+ 4.0.0
+ war
+ 1.0-SNAPSHOT
+ com.example.appengine
+ appengine-mailgun
+
+ com.google.cloud
+ doc-samples
+ 1.0.0
+ ../..
+
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+ jar
+ provided
+
+
+
+ com.sun.jersey
+ jersey-core
+ 1.19
+
+
+ com.sun.jersey
+ jersey-client
+ 1.19
+
+
+ com.sun.jersey.contribs
+ jersey-multipart
+ 1.19
+
+
+
+
+
+ ${project.build.directory}/${project.build.finalName}/WEB-INF/classes
+
+
+ org.apache.maven.plugins
+ 3.3
+ maven-compiler-plugin
+
+ 1.7
+ 1.7
+
+
+
+ com.google.appengine
+ appengine-maven-plugin
+ 1.9.31
+
+
+
+
diff --git a/appengine/mailgun/src/main/java/com/example/appengine/mailgun/MailgunServlet.java b/appengine/mailgun/src/main/java/com/example/appengine/mailgun/MailgunServlet.java
new file mode 100644
index 00000000000..6d03cc29449
--- /dev/null
+++ b/appengine/mailgun/src/main/java/com/example/appengine/mailgun/MailgunServlet.java
@@ -0,0 +1,94 @@
+/**
+ * Copyright 2015 Google Inc. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.appengine.mailgun;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import com.sun.jersey.multipart.FormDataMultiPart;
+import com.sun.jersey.multipart.file.FileDataBodyPart;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.MediaType;
+
+// [START example]
+@SuppressWarnings("serial")
+@WebServlet(name = "mailgun", value = "/send/email")
+public class MailgunServlet extends HttpServlet {
+
+ private static final String MAILGUN_DOMAIN_NAME = System.getenv("MAILGUN_DOMAIN_NAME");
+ private static final String MAILGUN_API_KEY = System.getenv("MAILGUN_API_KEY");
+
+ @Override
+ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ String type = req.getParameter("submit");
+ String recipient = req.getParameter("to");
+ ClientResponse clientResponse;
+ if (type.equals("Send simple email")) {
+ clientResponse = sendSimpleMessage(recipient);
+ } else {
+ clientResponse = sendComplexMessage(recipient);
+ }
+ if (clientResponse.getStatus() == 200) {
+ resp.getWriter().print("Email sent.");
+ }
+ }
+
+ // [START simple]
+ private ClientResponse sendSimpleMessage(String recipient) {
+ Client client = Client.create();
+ client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));
+ WebResource webResource = client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME
+ + "/messages");
+ MultivaluedMapImpl formData = new MultivaluedMapImpl();
+ formData.add("from", "Mailgun User ");
+ formData.add("to", recipient);
+ formData.add("subject", "Simple Mailgun Example");
+ formData.add("text", "Plaintext content");
+ return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class,
+ formData);
+ }
+ // [END simple]
+
+ // [START complex]
+ private ClientResponse sendComplexMessage(String recipient) {
+ Client client = Client.create();
+ client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));
+ WebResource webResource = client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME
+ + "/messages");
+ FormDataMultiPart formData = new FormDataMultiPart();
+ formData.field("from", "Mailgun User ");
+ formData.field("to", recipient);
+ formData.field("subject", "Complex Mailgun Example");
+ formData.field("html", "HTML content");
+ ClassLoader classLoader = getClass().getClassLoader();
+ File txtFile = new File(classLoader.getResource("example-attachment.txt").getFile());
+ formData.bodyPart(new FileDataBodyPart("attachment", txtFile, MediaType.TEXT_PLAIN_TYPE));
+ return webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE)
+ .post(ClientResponse.class, formData);
+ }
+ // [END complex]
+}
+// [END example]
diff --git a/appengine/mailgun/src/main/webapp/WEB-INF/appengine-web.xml b/appengine/mailgun/src/main/webapp/WEB-INF/appengine-web.xml
new file mode 100644
index 00000000000..f720d147b74
--- /dev/null
+++ b/appengine/mailgun/src/main/webapp/WEB-INF/appengine-web.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ YOUR-PROJECT-ID
+ YOUR-VERSION-ID
+ true
+
+
+
+
+
+
diff --git a/appengine/mailgun/src/main/webapp/WEB-INF/web.xml b/appengine/mailgun/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 00000000000..26e63250cbe
--- /dev/null
+++ b/appengine/mailgun/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+ mailgun
+ com.example.appengine.mailgun.MailgunServlet
+
+
+ mailgun
+ /send/email
+
+
+
diff --git a/appengine/mailgun/src/main/webapp/index.html b/appengine/mailgun/src/main/webapp/index.html
new file mode 100644
index 00000000000..6049c6945e7
--- /dev/null
+++ b/appengine/mailgun/src/main/webapp/index.html
@@ -0,0 +1,27 @@
+
+
+
+
+ Mailgun on Google App Engine Managed VMs
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 30a23aa7e92..df3183dcfab 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,6 +25,7 @@
appengine/appidentity
appengine/helloworld
+ appengine/mailgun
bigquery
datastore
logging