
This sample demonstrates how to use SendGrid on Google Compute Engine
See the sample application documentaion for more detailed instructions.
For more information about SendGrid, see their documentation.
To run the sample, you will need to do the following:
Create a SendGrid Account. As of September 2015, Google users start with 25,000 free emails per month.
Create a compute instance on the Google Cloud Platform Developer's Console
SSH into the instance you created
Update packages and install required packages
sudo apt-get update && sudo apt-get install git-core openjdk-8-jdk maven
Clone the repo
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
Configure your SendGrid settings in the java class (
SENDGRID_API_KEY
,SENDGRID_SENDER
,TO_EMAIL
)java-docs-samples/compute/sendgrid/src/main/java/com/example/compute/sendgrid/SendEmailServlet.java
Navigate back to
./sendgrid
and use maven to package the class as a jarmvn clean package
Switch to the target directory with the jar file and enable execution on that file
chmod +x compute-sendgrid-1.0-SNAPSHOT-jar-with-dependencies.jar
Make sure that openjdk 8 is the selected java version
sudo update-alternatives --config java
Execute the jar file and send an email (make sure you are in the target folder)
java -jar compute-sendgrid-1.0-SNAPSHOT-jar-with-dependencies.jar