Giter Site home page Giter Site logo

aws-samples / amazon-workmail-demo-ews-push-notifications Goto Github PK

View Code? Open in Web Editor NEW
9.0 2.0 4.0 18 KB

A sample application demonstrating the use of EWS Push Notifications. It creates a push responder using AWS Lambda and API Gateway to respond to changes in your mailbox.

License: Apache License 2.0

Java 100.00%

amazon-workmail-demo-ews-push-notifications's Introduction

WorkMail Push Notifications

WorkMail’s Push Notifications API allows customers to receive notifications about changes in their mailbox, such as receiving a new mail and updates in the calendar, by using its Push Notifications feature. Customers can register URL’s (push notification responders) which will then receive these notifications. This allows the development of responsive client applications, as they can quickly reflect changes in the mailbox in the user interface.

This sample presents a demo Push Notification responder running on top of AWS Lambda and API Gateway, using the AWS Serverless framework.

This demo contains two parts:

  • The first part consists of creating a subscription to the user’s mailbox. The subscription request consists of the URL of the push notification responder which will handle the notifications sent by the WorkMail service. The client responder is implemented using AWS Lambda (described in the second part).
  • The second part is to implement the push notification responder which handles notifications sent by the WorkMail service.

The push notification responder (Lambda handler) performs the following activities:

  • Receives the EWS XML notification and deserializes it.
  • If the notification contains any CreateItem events it downloads the subject and the body of the item.
  • If the subject contains a keyword ('demo') then the body is passed to AWS Comprehend (An AWS Service - https://aws.amazon.com/comprehend/) to detect the language and perform sentiment analysis.
  • The result is sent back to the sender in the form of a reply.

Prerequisites:

To run the demo application perform the following operations:

Steps

Check out the code package

git clone https://github.com/aws-samples/amazon-workmail-demo-ews-push-notifications

Compile the code

mvn clean package shade:shade

Package the code

aws cloudformation package --template-file template.yml --output-template-file output-template.yaml --s3-bucket <YOUR_S3_BUCKET_NAME>

Deploy the code

aws cloudformation deploy --template-file output-template.yaml --stack-name workmail-demo --capabilities CAPABILITY_IAM

This will create a CloudFormation stack with two functions: one which will invoke the Push Subscription API and another which will handle the notifications.

Inspect the output values of the cloud formation.

Validation

aws cloudformation describe-stacks | jq '.Stacks[] | select(.StackName == "workmail-demo").Outputs[].OutputValue'

The first is the API Gateway endpoint of the lambda response handler and the second is the ARN of the lambda function which subscribes to the mailbox events.

Credential Management

Both lambda functions require valid user credentials to access the WorkMail endpoint. The code assumes that the user password is stored encrypted in the AWS Systems Manager Parameter Store (SSM Parameter store - https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html).

To set the password in the SSM Parameter store, run the command below or use the AWS EC2 console to create the parameter. Note that the parameter name must match the user part of the email (e.g if the email address is [email protected] then the name of the parameter must be “john).

aws ssm put-parameter --name <USER> --value <PASSWORD> --type "SecureString"

To register a user's mailbox for push subscriptions run:

aws lambda invoke --function-name <SUBSCRIBE_LAMBDA_ARN> --payload  '{"email": "EMAIL"}' outputfile.txt

A successful run results in the following output in the console:

{
    "StatusCode": 200
}

To see the demo in action, send an email to the user subscribed for push subscriptions above with the subject "demo" from another user's account. The sender will then receive a reply consisting of the sentiment analysis of the content in the body of the initial email.

To stop subscriptions just delete the stored password from the SSM Parameter store:

aws ssm delete-parameter --name <USER>

Once the parameter is deleted the lambda notification responder will respond with 'Unsubscribe' when the next notification will be received.

To find out more about Amazon WorkMail, please visit Amazon WorkMail.

amazon-workmail-demo-ews-push-notifications's People

Contributors

markatwood avatar skoster-aws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

craigspaz

amazon-workmail-demo-ews-push-notifications's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.