Skip to content

Commit

Permalink
add tsl property (#11) (#12)
Browse files Browse the repository at this point in the history
Using TLS attributes if it is enabled via property

Co-authored-by: ManthanSharma94 <[email protected]>
  • Loading branch information
karthik-tarento and ManthanSharma94 authored Jan 17, 2023
1 parent 68e7fbf commit e0d6d71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class Constants {
public static final String EMAIL_SERVER_HOST = "sunbird_mail_server_host";
public static final String EMAIL_SERVER_PASSWORD = "sunbird_mail_server_password";
public static final String EMAIL_SERVER_PORT = "sunbird_mail_server_port";

public static final String Is_TLS_Enable = "sunbird_mail_server_use_tls";
public static final String EMAIL_SERVER_USERNAME = "sunbird_mail_server_username";
public static final String FROM_EMAIL = "fromEmail";
public static final String EMAIL_ORG_IMG_URL = "orgImageUrl";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class Email {
private static Properties props = null;
private String host;
private String port;

private String isTlsEnabled;
private String userName;
private String password;
private String fromEmail;
Expand Down Expand Up @@ -86,6 +88,7 @@ private boolean init() {
boolean response = true;
host = Util.readValue(Constants.EMAIL_SERVER_HOST);
port = Util.readValue(Constants.EMAIL_SERVER_PORT);
isTlsEnabled = Util.readValue(Constants.Is_TLS_Enable);
userName = Util.readValue(Constants.EMAIL_SERVER_USERNAME);
password = Util.readValue(Constants.EMAIL_SERVER_PASSWORD);
fromEmail = Util.readValue(Constants.EMAIL_SERVER_FROM);
Expand Down Expand Up @@ -128,6 +131,11 @@ private void initProps() {
props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.socketFactory.port", port);
if ("true".equalsIgnoreCase(isTlsEnabled))
{
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
}
/*
* props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
*/
Expand Down

0 comments on commit e0d6d71

Please sign in to comment.