azavea / osmesa

OSMesa is an OpenStreetMap processing stack based on GeoTrellis and Apache Spark
Apache License 2.0
79 stars 26 forks source link

Send SMTP Emails from StreamingAOIMonitor CLI #173

Closed CloudNiner closed 4 years ago

CloudNiner commented 4 years ago

Overview

This PR uses Apache Commons Email to send plain text emails to an unauthenticated SMTP endpoint as long as the environment variable AOI_FROM_ADDRESS is set and not empty. Otherwise, the CLI continues to default to publishing email messages to stdout.

Demo

I configured my environment with:

export AOI_FROM_ADDRESS=noreply@foo.com
export AOI_SMTP_HOSTNAME=localhost
export AOI_SMTP_PORT=1025

and started a MailHog container with:

docker run -p 8025:8025 -p 1025:1025 mailhog/mailhog

Then I ran the CLI from SBT after configuring some Notification objects in the connected Postgres database, something like:

./sbt
project analytics
 test:runMain osmesa.analytics.oneoffs.StreamingAOIMonitor --augmented-diff-source s3://bucket/path/to/augmented-diffs/ --interval d --start-sequence 3769420

SBT stdout looks like: Screen Shot 2019-11-19 at 5 46 18 PM

And we can verify that emails were properly sent via SMTP to the running mailhog endpoint by inspecting the web console provided by mailhog at http://localhost:8025 : Screen Shot 2019-11-19 at 5 46 13 PM

Success!