Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
Update send notification code
Browse files Browse the repository at this point in the history
This commit adds in an if else block in the TriggerEmail.java.
The code will check if email configuration is set before trying to send an email through cloud function or javamailsender.

Signed-off-by: AnthonyAmanse <[email protected]>
  • Loading branch information
AnthonyAmanse committed Jul 1, 2018
1 parent 95c057d commit 2854156
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,31 @@ private String sendEmail(@RequestBody Map<String, Object> 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<String> requestEntity = new HttpEntity<String>(json, headers);
ResponseEntity<String> 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<String> requestEntity = new HttpEntity<String>(json, headers);
ResponseEntity<String> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:}
2 changes: 1 addition & 1 deletion containers/transaction-generator/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 .

0 comments on commit 2854156

Please sign in to comment.