diff --git a/containers/send-notification/src/main/java/com/example/controller/TriggerEmail.java b/containers/send-notification/src/main/java/com/example/controller/TriggerEmail.java index 049a9440..03520b1e 100644 --- a/containers/send-notification/src/main/java/com/example/controller/TriggerEmail.java +++ b/containers/send-notification/src/main/java/com/example/controller/TriggerEmail.java @@ -48,26 +48,31 @@ private String sendEmail(@RequestBody Map payload) { MimeMessageHelper helper = new MimeMessageHelper(mail); try { - if (email_openwhisk_url.isEmpty()) { - helper.setTo(receiver); - helper.setFrom(sender); - helper.setReplyTo(sender); - helper.setSubject("Office-Space Notification"); - helper.setText("Account Balance is now over $50,000. " + payload.get("balance")); - mailSender.send(mail); - return "{\"message\": \"OK sent email via client\"}"; - } - else { - RestTemplate rest = new RestTemplate(); - HttpHeaders headers = new HttpHeaders(); - String server = email_openwhisk_url; - headers.add("Content-Type", "application/json"); - headers.add("Accept", "*/*"); - String json = "{\"text\": \"" + notification_message + ", " + payload.get("balance") + "\",\"sender\": \"" + sender + "\",\"receiver\": \"" + receiver + "\",\"password\": \"" + password + "\",\"subject\": \"Office-Space Notification\"}"; - HttpEntity requestEntity = new HttpEntity(json, headers); - ResponseEntity responseEntity = rest.exchange(server, HttpMethod.POST, requestEntity, String.class); - return "{\"message\": \"OK sent email via openwhisk\"}"; + if (!receiver.isEmpty() && !sender.isEmpty() && !password.isEmpty()) { + if (email_openwhisk_url.isEmpty()) { + helper.setTo(receiver); + helper.setFrom(sender); + helper.setReplyTo(sender); + helper.setSubject("Office-Space Notification"); + helper.setText("Account Balance is now over $50,000. " + payload.get("balance")); + mailSender.send(mail); + return "{\"message\": \"OK sent email via client\"}"; + } + else { + RestTemplate rest = new RestTemplate(); + HttpHeaders headers = new HttpHeaders(); + String server = email_openwhisk_url; + headers.add("Content-Type", "application/json"); + headers.add("Accept", "*/*"); + String json = "{\"text\": \"" + notification_message + ", " + payload.get("balance") + "\",\"sender\": \"" + sender + "\",\"receiver\": \"" + receiver + "\",\"password\": \"" + password + "\",\"subject\": \"Office-Space Notification\"}"; + + HttpEntity requestEntity = new HttpEntity(json, headers); + ResponseEntity responseEntity = rest.exchange(server, HttpMethod.POST, requestEntity, String.class); + return "{\"message\": \"OK sent email via openwhisk\"}"; + } + } else { + return "{\"message\": \"No email configuration specified. No email sent.\"}"; } } catch (Exception e) { // TODO Auto-generated catch block diff --git a/containers/send-notification/src/main/resources/application.properties b/containers/send-notification/src/main/resources/application.properties index 739c5bdc..067aa233 100644 --- a/containers/send-notification/src/main/resources/application.properties +++ b/containers/send-notification/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.mail.host=smtp.gmail.com -spring.mail.username=${GMAIL_SENDER_USER} -spring.mail.password=${GMAIL_SENDER_PASSWORD} +spring.mail.username=${GMAIL_SENDER_USER:} +spring.mail.password=${GMAIL_SENDER_PASSWORD:} spring.mail.properties.mail.smtp.auth = true; spring.mail.properties.mail.smtp.starttls.enable = true spring.mail.properties.mail.smtp.ssl.enable = true @@ -9,7 +9,7 @@ spring.mail.properties.mail.socketFactory.class=javax.net.ssl.SSLSocketFactory spring.mail.properties.mail.socketFactory.fallback=false spring.mail.smtp.port=587 -trigger.mail.receiver=${EMAIL_RECEIVER} -trigger.slack.url=${OPENWHISK_API_URL_SLACK} -trigger.notification.message=${NOTIFICATION_MESSAGE} -trigger.email.url=${OPENWHISK_API_URL_EMAIL} +trigger.mail.receiver=${EMAIL_RECEIVER:} +trigger.slack.url=${OPENWHISK_API_URL_SLACK:} +trigger.notification.message=${NOTIFICATION_MESSAGE:} +trigger.email.url=${OPENWHISK_API_URL_EMAIL:} diff --git a/containers/transaction-generator/Dockerfile b/containers/transaction-generator/Dockerfile index dd6297d9..b777ea68 100644 --- a/containers/transaction-generator/Dockerfile +++ b/containers/transaction-generator/Dockerfile @@ -1,4 +1,4 @@ FROM python:2.7.13 +ADD transaction-generator.py . RUN pip install requests CMD python transaction-generator.py -ADD transaction-generator.py . \ No newline at end of file