I just tried the App Engine Hello World example as the base and modified to accept incoming emails and it works for me. The destination email address format I used is recipient-user@PROJECT_ID.appspotmail.com
I would recommend you verify debugging using a development app server and verify the following:
Add some logging in your mail handler servlet when it gets the request. You can look at the example I've posted for some pointers.
Go to http://localhost:8080/_ah/admin/inboundmail
to access the Inbound Mail
page in Development Console
and send a test email from there.
If you look at the server logs, you should see the logs from your servlet (i.e. the ones you added in Step 1) if the configuration is correct.
Once you've confirmed everything works with the development app server, deploy your app to App Engine and test by sending a real email and look again at the Service logs through Stackdriver Logging. You should see 200 responses for such incoming mail requests in addition to the logs you added in Step 1.
Also note that many email providers will start throttling mails to a destination email ID if there is no successful response after few retries. This is another good reason to verify using a development app server first.
Here is the diff from the App Engine Hello World example where I got it working:
pom.xml
--- a/appengine/helloworld/pom.xml
+++ b/appengine/helloworld/pom.xml
@@ -33,6 +33,11 @@ Copyright 2015 Google Inc.
<version>2.5</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>1.5.0-b01</version>
+ </dependency>
</dependencies>
<build>
<!-- for hot reload of the web application -->
src/main/java/com/example/appengine/helloworld/MailHandlerServlet.java
--- /dev/null
+++ b/appengine/helloworld/src/main/java/com/example/appengine/helloworld/MailHandlerServlet.java
@@ -0,0 +1,36 @@
+package com.example.appengine.helloworld;
+
+import java.io.IOException;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.Properties;
+
+import javax.mail.Address;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class MailHandlerServlet extends HttpServlet {
+
+ private static final Logger log = Logger.getLogger(MailHandlerServlet.class.getName());
+
+ @Override
+ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ Properties props = new Properties();
+ Session session = Session.getDefaultInstance(props, null);
+ try {
+ MimeMessage message = new MimeMessage(session, req.getInputStream());
+ log.info("Received mail message content type: " + message.getContentType());
+ for (Address addr : message.getFrom()) {
+ log.info("Received mail from: " + addr);
+ }
+ } catch (MessagingException e) {
+ log.log(Level.SEVERE, "Failed to handle incoming message:", e);
+ }
+ // ...
+ }
+}
src/main/webapp/WEB-INF/appengine-web.xml
--- a/appengine/helloworld/src/main/webapp/WEB-INF/appengine-web.xml
+++ b/appengine/helloworld/src/main/webapp/WEB-INF/appengine-web.xml
@@ -13,8 +13,11 @@
-->
<!-- [START config] -->
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>YOUR-PROJECT-ID</application>
<version>YOUR-VERSION-ID</version>
<threadsafe>true</threadsafe>
+ <inbound-services>
+ <service>mail</service>
+ </inbound-services>
</appengine-web-app>
<!-- [END config] -->
src/main/webapp/WEB-INF/web.xml
--- a/appengine/helloworld/src/main/webapp/WEB-INF/web.xml
+++ b/appengine/helloworld/src/main/webapp/WEB-INF/web.xml
@@ -7,8 +7,17 @@
<servlet-name>hello</servlet-name>
<servlet-class>com.example.appengine.helloworld.HelloServlet</servlet-class>
</servlet>
+ <servlet>
+ <servlet-name>mailhandler</servlet-name>
+ <servlet-class>com.example.appengine.helloworld.MailHandlerServlet</servlet-class>
+ </servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>mailhandler</servlet-name>
+ <!-- /_ah/mail/* matches all email addressed to the app -->
+ <url-pattern>/_ah/mail/*</url-pattern>
+ </servlet-mapping>
</web-app>