-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add mailjet samples #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mailjet samples #146
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Remove unused annotation in mailgun
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Mailjet sample for Google App Engine | ||
| This sample demonstrates how to use [Mailjet](https://www.mailjet.com/) on Google App Engine. | ||
|
|
||
| ## Setup | ||
| 1. Before using, ensure the address you plan to send from has been verified in Mailjet. | ||
|
|
||
| ## Running locally | ||
| $ export MAILJET_API_KEY=[your mailjet api key] | ||
| $ export MAILJET_SECRET_KEY=[your mailjet secret key] | ||
| $ mvn clean appengine:devserver | ||
|
|
||
| ## Deploying | ||
| 1. Edit the environment variables in the appengine-web.xml with the appropriate Mailjet values. | ||
| $ mvn clean appengine:update | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <project> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <packaging>war</packaging> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <groupId>com.example.appengine</groupId> | ||
| <artifactId>appengine-mailjet</artifactId> | ||
| <parent> | ||
| <groupId>com.google.cloud</groupId> | ||
| <artifactId>doc-samples</artifactId> | ||
| <version>1.0.0</version> | ||
| <relativePath>../..</relativePath> | ||
| </parent> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.mailjet</groupId> | ||
| <artifactId>mailjet-client</artifactId> | ||
| <version>3.1.1</version> | ||
| <scope>system</scope> | ||
| <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/client-3.1.1-jar-with-dependencies.jar</systemPath> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>javax.servlet</groupId> | ||
| <artifactId>javax.servlet-api</artifactId> | ||
| <version>3.1.0</version> | ||
| <type>jar</type> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <!-- [START dependencies] --> | ||
| <dependency> | ||
| <groupId>com.sun.jersey</groupId> | ||
| <artifactId>jersey-core</artifactId> | ||
| <version>1.19.1</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.sun.jersey</groupId> | ||
| <artifactId>jersey-client</artifactId> | ||
| <version>1.19.1</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.sun.jersey.contribs</groupId> | ||
| <artifactId>jersey-multipart</artifactId> | ||
| <version>1.19.1</version> | ||
| </dependency> | ||
| <!-- [END dependencies] --> | ||
| </dependencies> | ||
| <build> | ||
| <!-- for hot reload of the web application --> | ||
| <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>com.google.appengine</groupId> | ||
| <artifactId>appengine-maven-plugin</artifactId> | ||
| <version>${appengine.sdk.version}</version> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.example.appengine.mailjet; | ||
|
||
|
|
||
| import org.json.JSONArray; | ||
| import org.json.JSONObject; | ||
|
|
||
| import com.mailjet.client.MailjetClient; | ||
| import com.mailjet.client.MailjetRequest; | ||
| import com.mailjet.client.MailjetResponse; | ||
| import com.mailjet.client.errors.MailjetException; | ||
| import com.mailjet.client.resource.Email; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import javax.servlet.ServletException; | ||
| import javax.servlet.http.HttpServlet; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| @SuppressWarnings("serial") | ||
| public class MailjetServlet extends HttpServlet { | ||
| private static final String MAILJET_API_KEY = System.getenv("MAILJET_API_KEY"); | ||
| private static final String MAILJET_SECRET_KEY = System.getenv("MAILJET_SECRET_KEY"); | ||
| private MailjetClient client = new MailjetClient(MAILJET_API_KEY, MAILJET_SECRET_KEY); | ||
|
|
||
| @Override | ||
| public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, | ||
| ServletException { | ||
| String recipient = req.getParameter("to"); | ||
| String sender = req.getParameter("from"); | ||
|
|
||
| MailjetRequest email = new MailjetRequest(Email.resource) | ||
| .property(Email.FROMEMAIL, sender) | ||
| .property(Email.FROMNAME, "pandora") | ||
| .property(Email.SUBJECT, "Your email flight plan!") | ||
| .property(Email.TEXTPART, | ||
| "Dear passenger, welcome to Mailjet! May the delivery force be with you!") | ||
| .property(Email.HTMLPART, | ||
| "<h3>Dear passenger, welcome to Mailjet!</h3><br/>May the delivery force be with you!") | ||
| .property(Email.RECIPIENTS, | ||
| new JSONArray().put(new JSONObject().put("Email", recipient))); | ||
|
|
||
| try { | ||
| // trigger the API call | ||
| MailjetResponse response = client.post(email); | ||
| // Read the response data and status | ||
| resp.getWriter().print(response.getStatus()); | ||
| resp.getWriter().print(response.getData()); | ||
| } catch (MailjetException e) { | ||
| throw new ServletException("Mailjet Exception", e); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. License & Copyright? |
||
| <appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> | ||
| <application>YOUR-PROJECT-ID</application> | ||
| <version>YOUR-VERSION-ID</version> | ||
| <threadsafe>true</threadsafe> | ||
| <env-variables> | ||
| <env-var name="MAILJET_API_KEY" value="YOUR-MAILJET-API-KEY" /> | ||
| <env-var name="MAILJET_SECRET_KEY" value="YOUR-MAILJET-SECRET-KEY" /> | ||
| </env-variables> | ||
| </appengine-web-app> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. License & Copyright? |
||
| <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" | ||
| xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
| xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
| version="2.5"> | ||
| <servlet> | ||
| <servlet-name>mailjet</servlet-name> | ||
| <servlet-class>com.example.appengine.mailjet.MailjetServlet</servlet-class> | ||
| </servlet> | ||
| <servlet-mapping> | ||
| <servlet-name>mailjet</servlet-name> | ||
| <url-pattern>/send/email</url-pattern> | ||
| </servlet-mapping> | ||
| </web-app> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <!doctype html> | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <html> | ||
| <head> | ||
| <title>Mailgun on Google App Engine Managed VMs</title> | ||
| </head> | ||
| <body> | ||
| <!-- [START form] --> | ||
| <form method="post" action="/send/email"> | ||
| <input type="text" name="to" placeholder="Enter recipient email"> | ||
| <input type="text" name="from" placeholder="Enter sender email"> | ||
| <input type="submit" name="submit" value="Send email"> | ||
| </form> | ||
| <!-- [END form] --> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Mailjet sample for Google Managed VMs | ||
| This sample demonstrates how to use [Mailjet](https://www.mailjet.com/) on Google Managed VMs. | ||
|
|
||
| ## Setup | ||
| 1. Before using, ensure the address you plan to send from has been verified in Mailjet. | ||
|
|
||
| ## Running locally | ||
| $ export MAILJET_API_KEY=[your mailjet api key] | ||
| $ export MAILJET_SECRET_KEY=[your mailjet secret key] | ||
| $ mvn clean jetty:run | ||
|
|
||
| ## Deploying | ||
| 1. Edit the environment variables in the app.yaml with the appropriate Mailjet values. | ||
| $ mvn clean gcloud:deploy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <project> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <packaging>war</packaging> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <groupId>com.example.managedvms</groupId> | ||
| <artifactId>managed-vms-mailjet</artifactId> | ||
| <parent> | ||
| <groupId>com.google.cloud</groupId> | ||
| <artifactId>doc-samples</artifactId> | ||
| <version>1.0.0</version> | ||
| <relativePath>../..</relativePath> | ||
| </parent> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.mailjet</groupId> | ||
| <artifactId>mailjet-client</artifactId> | ||
| <version>3.1.1</version> | ||
| <scope>system</scope> | ||
| <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/client-3.1.1-jar-with-dependencies.jar</systemPath> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>javax.servlet</groupId> | ||
| <artifactId>javax.servlet-api</artifactId> | ||
| <version>3.1.0</version> | ||
| <type>jar</type> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <!-- [START dependencies] --> | ||
| <dependency> | ||
| <groupId>com.sun.jersey</groupId> | ||
| <artifactId>jersey-core</artifactId> | ||
| <version>1.19.1</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.sun.jersey</groupId> | ||
| <artifactId>jersey-client</artifactId> | ||
| <version>1.19.1</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.sun.jersey.contribs</groupId> | ||
| <artifactId>jersey-multipart</artifactId> | ||
| <version>1.19.1</version> | ||
| </dependency> | ||
| <!-- [END dependencies] --> | ||
| </dependencies> | ||
| <build> | ||
| <!-- for hot reload of the web application --> | ||
| <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>com.google.appengine</groupId> | ||
| <artifactId>gcloud-maven-plugin</artifactId> | ||
| <version>2.0.9.101.v20160316</version> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-war-plugin</artifactId> | ||
| <version>2.6</version> | ||
| <configuration> | ||
| <failOnMissingWebXml>false</failOnMissingWebXml> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <version>3.3</version> | ||
| <artifactId>maven-compiler-plugin</artifactId> | ||
| <configuration> | ||
| <source>1.8</source> | ||
| <target>1.8</target> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.eclipse.jetty</groupId> | ||
| <artifactId>jetty-maven-plugin</artifactId> | ||
| <version>9.3.7.v20160115</version> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| runtime: java | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. License & Copyright? |
||
| vm: true | ||
|
|
||
| handlers: | ||
| - url: /.* | ||
| script: this field is required, but ignored | ||
| secure: always | ||
|
|
||
| # [START env_variables] | ||
| env_variables: | ||
| MAILJET_API_KEY: YOUR-MAILJET-API-KEY | ||
| MAILJET_SECRET_KEY: YOUR-MAILJET-SECRET-KEY | ||
| # [END env_variables] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.example.managedvms.mailjet; | ||
|
||
|
|
||
| import org.json.JSONArray; | ||
| import org.json.JSONObject; | ||
|
|
||
| import com.mailjet.client.MailjetClient; | ||
| import com.mailjet.client.MailjetRequest; | ||
| import com.mailjet.client.MailjetResponse; | ||
| import com.mailjet.client.errors.MailjetException; | ||
| import com.mailjet.client.resource.Email; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import javax.servlet.ServletException; | ||
| import javax.servlet.annotation.WebServlet; | ||
| import javax.servlet.http.HttpServlet; | ||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
|
|
||
| @SuppressWarnings("serial") | ||
| @WebServlet(name = "mailjet", value = "/send/email") | ||
| public class MailjetServlet extends HttpServlet { | ||
| private static final String MAILJET_API_KEY = System.getenv("MAILJET_API_KEY"); | ||
| private static final String MAILJET_SECRET_KEY = System.getenv("MAILJET_SECRET_KEY"); | ||
| private MailjetClient client = new MailjetClient(MAILJET_API_KEY, MAILJET_SECRET_KEY); | ||
|
|
||
| @Override | ||
| public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, | ||
| ServletException { | ||
| String recipient = req.getParameter("to"); | ||
| String sender = req.getParameter("from"); | ||
|
|
||
| MailjetRequest email = new MailjetRequest(Email.resource) | ||
| .property(Email.FROMEMAIL, sender) | ||
| .property(Email.FROMNAME, "pandora") | ||
| .property(Email.SUBJECT, "Your email flight plan!") | ||
| .property(Email.TEXTPART, | ||
| "Dear passenger, welcome to Mailjet! May the delivery force be with you!") | ||
| .property(Email.HTMLPART, | ||
| "<h3>Dear passenger, welcome to Mailjet!</h3><br/>May the delivery force be with you!") | ||
| .property(Email.RECIPIENTS, | ||
| new JSONArray().put(new JSONObject().put("Email", recipient))); | ||
|
|
||
| try { | ||
| // trigger the API call | ||
| MailjetResponse response = client.post(email); | ||
| // Read the response data and status | ||
| resp.getWriter().print(response.getStatus()); | ||
| resp.getWriter().print(response.getData()); | ||
| } catch (MailjetException e) { | ||
| throw new ServletException("Mailjet Exception", e); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This really should say more.