[Solved] Java Google App Engine won’t send email via Mailgun SMTP


I’m guessing you are talking about this tutorial to configure the sending of mails through Compute Engine (which explains why it works well on your VM instance).

That tutorial is for Compute Engine, in the case of App Engine Standard applications, you have the option of using Mail API, however, since Google is no longer accepting quota increases for that API, is advised to use a third-party service such as MailGun or SendGrid.

To connect your App Engine standard application (with Java runtime) with those third-party services you will need to specify the “dependicies” on your “pom.xml” file and modify your “app.yaml” with the API Key:

env_variables:
     EMAIL_API_KEY: key-from-third-party 

The Email API Key will be provided by the third-party service, for example, in the case of MailGun, their documentation specifies the following:

When you sign up for an account, you are given an API key. You
authenticate to the Mailgun API by providing your API key in the
request. You can manage your API key in the “Security” tab under the
Account section of the Control Panel.

For the step by step instructions on how to configure your App Engine Standard App to connect with these third-party services, please refer to this documentation.

EDIT:

It looks like in your case, you could be using another dependencies (hence, the dependency error). When you created the code did you refereed to the App Engine Java 8 documentation samples or to the Mailgun samples? because I noticed they use different dependencies, and also the App Engine sample uses env variables (which according to the snippet code you shared, you are not using).

My advice is to follow the sample given for Google App Engine Standard Java 8.

These are the steps I took to get the sample successfully up and running on App Engine:

1. Downloaded the sample code.

2. Created an account on Mailgun (simple account, not credit data attached). You will need to verify your account through the specified email.

3. Once your are logged inside MailGun, you will see a menu on the left, navigate to Sending > Overview page.

4. At the right you will see an “Authorized Recipients” box, add the email or the person that will receive the email, they will need to confirm also on their side, so try adding an email on which you have access for the sake of the test. Note: you need to do this if you haven’t verified your domain.

5. Copy the value of the domain you have for default (or the one you have verified).

6. On the same box there’s a menu with the link to “Api Keys”, click on it and copy the key under “HTTP webhook signing key” (this is also your private key, so be careful where you put it).

7. Head to the GCP sample that was downloaded, and edit the file “/mailgun/src/main/webapp/WEB-INF/appengine-web.xml” with those values (domain and key).

8. If you are using Maven run the commands:

mvn appengine:run  (if you want to test locally)

or

mvn appengine:deploy (if you want to deploy to App Engine) 

note: some of these steps might have look rather obvious for you but I have explained it this way so other people can follow it as well.

11

solved Java Google App Engine won’t send email via Mailgun SMTP