Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src/main/java/com/example/compute/sendgrid
README.md
pom.xml

README.md

Java SendGrid Email Sample for Google Compute Engine

Open in Cloud Shell

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.

Running on Compute Engine

To run the sample, you will need to do the following:

  1. Create a SendGrid Account. As of September 2015, Google users start with 25,000 free emails per month.

  2. Create a compute instance on the Google Cloud Platform Developer's Console

  3. SSH into the instance you created

  4. Update packages and install required packages

     sudo apt-get update && sudo apt-get install git-core openjdk-8-jdk maven
    
  5. Clone the repo

     git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
    
  6. 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
    
  7. Navigate back to ./sendgrid and use maven to package the class as a jar

     mvn clean package
    
  8. 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
    
  9. Make sure that openjdk 8 is the selected java version

     sudo update-alternatives --config java
    
  10. 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
    
You can’t perform that action at this time.