diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/EmailConfig.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/EmailConfig.java index 6a3de54a96..b0283d7381 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/EmailConfig.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/EmailConfig.java @@ -13,4 +13,9 @@ public class EmailConfig { @Value("${mail.enabled}") private boolean emailEnabled = true; + @Value("${mail.from}") + private String mailFrom; + + @Value("${reply.to}") + private String replyTo; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/notifications/EmailSender.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/notifications/EmailSender.java index b41d544f3e..5bac64dab0 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/notifications/EmailSender.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/notifications/EmailSender.java @@ -9,6 +9,7 @@ import org.springframework.mail.MailException; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; import reactor.core.Exceptions; import reactor.core.publisher.Mono; @@ -30,7 +31,9 @@ public class EmailSender { final EmailConfig emailConfig; - private static final InternetAddress MAIL_FROM = makeFromAddress(); + private final InternetAddress MAIL_FROM; + + private final InternetAddress REPLY_TO; public static final Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE); @@ -38,6 +41,9 @@ public class EmailSender { public EmailSender(JavaMailSender javaMailSender, EmailConfig emailConfig) { this.javaMailSender = javaMailSender; this.emailConfig = emailConfig; + + MAIL_FROM = makeFromAddress(); + REPLY_TO = makeReplyTo(); } private static boolean validateEmail(String emailStr) { @@ -75,11 +81,6 @@ public class EmailSender { return; } - if (MAIL_FROM == null) { - log.error("MAIL_FROM is null, no From address object to send an email. Not sending email '{}'.", subject); - return; - } - // Check if the email address is valid. It's possible for certain OAuth2 providers to not return the email ID if (to == null || !validateEmail(to)) { log.error("The email ID: {} is not valid. Not sending an email", to); @@ -92,7 +93,12 @@ public class EmailSender { try { helper.setTo(to); - helper.setFrom(MAIL_FROM); + if (MAIL_FROM != null) { + helper.setFrom(MAIL_FROM); + } + if (REPLY_TO != null) { + helper.setReplyTo(REPLY_TO); + } helper.setSubject(subject); helper.setText(text, true); javaMailSender.send(mimeMessage); @@ -120,11 +126,20 @@ public class EmailSender { return stringWriter.toString(); } - private static InternetAddress makeFromAddress() { + private InternetAddress makeFromAddress() { try { - return new InternetAddress("hello@appsmith.com", "Appsmith"); + return new InternetAddress(this.emailConfig.getMailFrom(), "Appsmith"); } catch (UnsupportedEncodingException e) { - log.error("Encoding error creating Appsmith from address.", e); + log.error("Encoding error creating Appsmith mail from address.", e); + return null; + } + } + + private InternetAddress makeReplyTo() { + try { + return new InternetAddress(this.emailConfig.getReplyTo(), "Appsmith"); + } catch (UnsupportedEncodingException e) { + log.error("Encoding error creating Appsmith reply to address.", e); return null; } } diff --git a/app/server/appsmith-server/src/main/resources/application.properties b/app/server/appsmith-server/src/main/resources/application.properties index ddfc441f92..7da471c346 100644 --- a/app/server/appsmith-server/src/main/resources/application.properties +++ b/app/server/appsmith-server/src/main/resources/application.properties @@ -43,6 +43,8 @@ spring.redis.url=${APPSMITH_REDIS_URL} # default localhost:25 SMTP server and throw an error. If false, this error won't happen because there's no attempt # to send an email. mail.enabled=${APPSMITH_MAIL_ENABLED:false} +mail.from=${APPSMITH_MAIL_FROM:appsmith@localhost} +reply.to=${APPSMITH_REPLY_TO:appsmith@localhost} spring.mail.host=${APPSMITH_MAIL_HOST:} spring.mail.port=${APPSMITH_MAIL_PORT:} spring.mail.username=${APPSMITH_MAIL_USERNAME:} diff --git a/deploy/template/docker.env.sh b/deploy/template/docker.env.sh index e322ee0118..bd88fefb2e 100644 --- a/deploy/template/docker.env.sh +++ b/deploy/template/docker.env.sh @@ -13,6 +13,8 @@ cat > docker.env << EOF # ***** Email ********** APPSMITH_MAIL_ENABLED=false +# APPSMITH_MAIL_FROM= +# APPSMITH_REPLY_TO= # APPSMITH_MAIL_HOST= # APPSMITH_MAIL_PASSWORD= # APPSMITH_MAIL_PORT=