Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS SES #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# killbill-email-notifications-plugin
![Maven Central](https://img.shields.io/maven-central/v/org.kill-bill.billing.plugin.java/killbill-email-notifications-plugin?color=blue&label=Maven%20Central)

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.
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.

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.

## Requirements

Expand Down Expand Up @@ -98,5 +100,9 @@ public class Activator extends KillbillActivatorBase {
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:

```

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
```

## AWS SES

Refer to the [plugin configuration](https://docs.killbill.io/latest/email-notification-plugin#plugin_configuration) section for instructions on setting up AWS SES.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly check my reply on that PR.

Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public class EmailSender {
private static final String DEBUG_LOG_ONLY = "org.killbill.billing.plugin.notification.email.logOnly";

private static final String EMAIL_NOTIFICATION_VIA_SES = "org.killbill.email.notification.via.ses";
private static final String AWS_REGION = "org.killbill.aws.region";
private static final String AWS_REGION_PROP = "org.killbill.aws.region";

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

private final boolean useSmtpAuth;
private final int useSmtpPort;
Expand All @@ -94,7 +94,7 @@ public EmailSender(final OSGIConfigPropertiesService configProperties) {
(configProperties.getString(IS_SMTP_AUTH_PROP) != null && Boolean.parseBoolean(configProperties.getString(IS_SMTP_AUTH_PROP))),
(configProperties.getString(IS_USE_SSL_PROP) != null && Boolean.parseBoolean(configProperties.getString(IS_USE_SSL_PROP))),
(configProperties.getString(DEBUG_LOG_ONLY) != null && Boolean.parseBoolean(configProperties.getString(DEBUG_LOG_ONLY))),
(configProperties.getString(AWS_REGION) != null ? configProperties.getString(AWS_REGION) : DEFAULT_AWS_REGION),
(configProperties.getString(AWS_REGION_PROP) != null ? configProperties.getString(AWS_REGION_PROP) : DEFAULT_AWS_REGION),
(configProperties.getString(EMAIL_NOTIFICATION_VIA_SES) != null && Boolean.parseBoolean(configProperties.getString(EMAIL_NOTIFICATION_VIA_SES))));
}

Expand All @@ -112,6 +112,12 @@ public EmailSender(final String smtpServerName, final int useSmtpPort, final Str
this.logOnly = logOnly;
this.awsRegion = awsRegion;
this.sendEmailsViaSES = sendEmailsViaSES;

if (sendEmailsViaSES) {
logger.info("Emails will be sent using AWS SES");
} else {
logger.info("Emails will be sent using SMTP");
}
}

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

logger.debug("Setting up AWS SES...");
if (logOnly) {
logger.info("Logging only mode is enabled. Skipping email sending.");

return;
}

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

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

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

client.sendEmail(request);

logger.info("Email sent successfully to={}, cc={}, subject={}", to, cc, subject);
}

private void validateEmailFields(final List<String> to, final List<String> cc, final String subject,
Expand Down
Loading