Skip to content

Commit 4bbc976

Browse files
authored
Merge pull request #60 from vnandwana/master
AWS SES
2 parents 488471a + b9a1e35 commit 4bbc976

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# killbill-email-notifications-plugin
22
![Maven Central](https://img.shields.io/maven-central/v/org.kill-bill.billing.plugin.java/killbill-email-notifications-plugin?color=blue&label=Maven%20Central)
33

4-
The Kill Bill email notification plugin is a plugin that can be used to send emails when certain events occur. The easiest way to get started with the email notification plugin is to take a look at our [Email Notification Plugin Document](https://docs.killbill.io/latest/email-notification-plugin.html) which provides detailed instructions for installing, configuring and using the plugin.
4+
The Kill Bill email notification plugin is a plugin that can be used to send emails when certain events occur. It supports sending notifications via either SMTP or AWS SES.
5+
6+
The easiest way to get started with the email notification plugin is to take a look at our [Email Notification Plugin Document](https://docs.killbill.io/latest/email-notification-plugin.html) which provides detailed instructions for installing, configuring and using the plugin.
57

68
## Requirements
79

@@ -98,5 +100,9 @@ public class Activator extends KillbillActivatorBase {
98100
In order to test the plugin, the easiest route is to start a local SMTP server. We are typically relying on the `namshi/smtp` docker image:
99101

100102
```
101-
102103
Replace `<jar_file_path>` with the path of the email notification plugin jar file and `<path_to_install_plugin>` with the path where you want to install the plugin. This path should match the path specified by the `org.killbill.osgi.bundle.install.dir` property in the Kill Bill configuration file
104+
```
105+
106+
## AWS SES
107+
108+
Refer to the [plugin configuration](https://docs.killbill.io/latest/email-notification-plugin#plugin_configuration) section for instructions on setting up AWS SES.

src/main/java/org/killbill/billing/plugin/notification/email/EmailSender.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public class EmailSender {
6767
private static final String DEBUG_LOG_ONLY = "org.killbill.billing.plugin.notification.email.logOnly";
6868

6969
private static final String EMAIL_NOTIFICATION_VIA_SES = "org.killbill.email.notification.via.ses";
70-
private static final String AWS_REGION = "org.killbill.aws.region";
70+
private static final String AWS_REGION_PROP = "org.killbill.aws.region";
7171

72-
private static final String DEFAULT_AWS_REGION = "US_EAST_1";
72+
private static final String DEFAULT_AWS_REGION = "us-east-1";
7373

7474
private final boolean useSmtpAuth;
7575
private final int useSmtpPort;
@@ -94,7 +94,7 @@ public EmailSender(final OSGIConfigPropertiesService configProperties) {
9494
(configProperties.getString(IS_SMTP_AUTH_PROP) != null && Boolean.parseBoolean(configProperties.getString(IS_SMTP_AUTH_PROP))),
9595
(configProperties.getString(IS_USE_SSL_PROP) != null && Boolean.parseBoolean(configProperties.getString(IS_USE_SSL_PROP))),
9696
(configProperties.getString(DEBUG_LOG_ONLY) != null && Boolean.parseBoolean(configProperties.getString(DEBUG_LOG_ONLY))),
97-
(configProperties.getString(AWS_REGION) != null ? configProperties.getString(AWS_REGION) : DEFAULT_AWS_REGION),
97+
(configProperties.getString(AWS_REGION_PROP) != null ? configProperties.getString(AWS_REGION_PROP) : DEFAULT_AWS_REGION),
9898
(configProperties.getString(EMAIL_NOTIFICATION_VIA_SES) != null && Boolean.parseBoolean(configProperties.getString(EMAIL_NOTIFICATION_VIA_SES))));
9999
}
100100

@@ -112,6 +112,12 @@ public EmailSender(final String smtpServerName, final int useSmtpPort, final Str
112112
this.logOnly = logOnly;
113113
this.awsRegion = awsRegion;
114114
this.sendEmailsViaSES = sendEmailsViaSES;
115+
116+
if (sendEmailsViaSES) {
117+
logger.info("Emails will be sent using AWS SES");
118+
} else {
119+
logger.info("Emails will be sent using SMTP");
120+
}
115121
}
116122

117123
// Backward compatibility. If no configuration exists, then reuse Kill Bill email properties
@@ -214,12 +220,16 @@ private void sendEmailViaSMTP(final List<String> to, final List<String> cc, fina
214220
private void sendEmailViaSES(final List<String> to, final List<String> cc, final String subject,
215221
final String body, final SmtpProperties smtp) {
216222

223+
logger.debug("Setting up AWS SES...");
217224
if (logOnly) {
225+
logger.info("Logging only mode is enabled. Skipping email sending.");
226+
218227
return;
219228
}
220229

221230
final Regions region = Regions.valueOf(awsRegion.replace("-", "_").toUpperCase());
222231

232+
logger.debug("Creating AWS SES client...");
223233
final AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.standard()
224234
.withRegion(region)
225235
.build();
@@ -231,11 +241,13 @@ private void sendEmailViaSES(final List<String> to, final List<String> cc, final
231241
.withText(new Content().withCharset("UTF-8").withData(body)))
232242
.withSubject(new Content()
233243
.withCharset("UTF-8").withData(subject)))
234-
.withSource(smtp.getFrom());
244+
.withSource(this.from);
235245

236246
logger.info("Sending email to={}, cc={}, subject={}", to, cc, subject);
237247

238248
client.sendEmail(request);
249+
250+
logger.info("Email sent successfully to={}, cc={}, subject={}", to, cc, subject);
239251
}
240252

241253
private void validateEmailFields(final List<String> to, final List<String> cc, final String subject,

0 commit comments

Comments
 (0)