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

BI-2101 - Configure Transactional Email for Production DeltaBreed #351

Merged
merged 6 commits into from
May 3, 2024
Merged
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
8 changes: 5 additions & 3 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ BRAPI_REFERENCE_SOURCE=breedinginsight.org
WEB_BASE_URL=http://localhost:8080

# Email server
EMAIL_RELAY_HOST=mailhog
EMAIL_RELAY_PORT=1025
[email protected]
EMAIL_RELAY_HOST=<mailhog for development, email-smtp.us-east-1.amazonaws.com for production>
EMAIL_RELAY_PORT=<1025 for development, 25 for production>
[email protected]
#EMAIL_RELAY_LOGIN=<blank for development>
#EMAIL_RELAY_PASSWORD=<blank for development>

GIGWA_HOST=<gigwa host (including port)>
GIGWA_USER=<username>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ private void sendAccountSignUpEmail(BiUserEntity user, SignedJWT jwtToken) {
emailTemplate.add("expiration_time", expirationTime);

String filledBody = emailTemplate.render();
String subject = "New Account Sign Up";
String subject = "Activate DeltaBreed Account";

// Send email
emailUtil.sendEmail(user.getEmail(), subject, filledBody);
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/org/breedinginsight/utilities/email/EmailUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

import io.micronaut.context.annotation.Property;
import io.micronaut.http.server.exceptions.HttpServerException;
import org.apache.commons.lang3.StringUtils;

import javax.inject.Singleton;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.UnsupportedEncodingException;
Expand All @@ -40,13 +38,29 @@ public class EmailUtil {
private Integer smtpHostPort;
@Property(name = "email.from")
private String fromEmail;
@Property(name = "email.relay-server.login")
private String smtpLogin;
@Property(name = "email.relay-server.password")
private String smtpPassword;

private Session getSmtpHost() {
Properties props = new Properties();
props.put("mail.smtp.host", smtpHostServer);
props.put("mail.smtp.port", smtpHostPort);
props.put("mail.debug", true);
return Session.getInstance(props, null);
Authenticator auth = null;
if (StringUtils.isNotBlank(smtpLogin) && StringUtils.isNotBlank(smtpPassword)) {
props.put("mail.smtp.auth", true);
props.put("mail.smtp.ssl.trust", smtpHostServer);
props.put("mail.smtp.starttls.enable", true);
auth = new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(smtpLogin, smtpPassword);
}
};
}
return Session.getInstance(props, auth);
}

public void sendEmail(String toEmail, String subject, String body){
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ email:
relay-server:
host: ${EMAIL_RELAY_HOST}
port: ${EMAIL_RELAY_PORT}
login: ${EMAIL_RELAY_LOGIN:null}
password: ${EMAIL_RELAY_PASSWORD:null}
from: ${EMAIL_FROM}

redisson:
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/email/newAccountEmail.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Welcome to Breeding Insight!

We use a common login system with ORCID to provide authentication and account security. You will need a current ORCID iD and account to log in to Breeding Insight. If you do not already have an ORCID iD, you can create one here: https://orcid.org/register

To activate your Breeding Insight account and connect your ORCID iD to Breeding Insight, use this link:
To activate your DeltaBreed account and connect your ORCID iD to DeltaBreed, use this link:

<new_signup_link>

Expand Down
Loading