Skip to content

Commit

Permalink
Merge pull request #42 from SeunMatt/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
SeunMatt authored Jul 31, 2024
2 parents e803f2f + 0d3f5a8 commit 52b4d9a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ properties.setProperty(MysqlExportService.EMAIL_USERNAME, "mailtrap-username");
properties.setProperty(MysqlExportService.EMAIL_PASSWORD, "mailtrap-password");
properties.setProperty(MysqlExportService.EMAIL_FROM, "[email protected]");
properties.setProperty(MysqlExportService.EMAIL_TO, "[email protected]");
properties.setProperty(MysqlExportService.EMAIL_SSL_PROTOCOLS, "TLSv1.2"); //this is optional

//optional email configs
properties.setProperty(MysqlExportService.EMAIL_SSL_PROTOCOLS, "TLSv1.2");
properties.setProperty(MysqlExportService.EMAIL_SMTP_AUTH_ENABLED, "true");
properties.setProperty(MysqlExportService.EMAIL_START_TLS_ENABLED, "true");

//set the outputs temp dir
properties.setProperty(MysqlExportService.TEMP_DIR, new File("external").getPath());
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/smattme/EmailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class EmailService {
private String subject = "";
private String msg = "";
private String sslProtocols = "TLSv1.2";
private String startTlsEnabled = "true";
private boolean smtpAuthEnabled = true;
private File [] attachments;
private Logger logger = LoggerFactory.getLogger(EmailService.class);
private final String LOG_PREFIX = "java-mysql-exporter";
Expand Down Expand Up @@ -92,6 +94,16 @@ EmailService setSslProtocols(String sslProtocols) {
return this;
}

EmailService setStartTlsEnabled(String startTlsEnabled) {
this.startTlsEnabled = startTlsEnabled;
return this;
}

EmailService setSmtpAuthEnabled(boolean smtpAuthEnabled) {
this.smtpAuthEnabled = smtpAuthEnabled;
return this;
}

/**
* This will check if the necessary properties
* are set for sending an email successfully
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/smattme/MysqlExportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class MysqlExportService {
public static final String EMAIL_FROM = "EMAIL_FROM";
public static final String EMAIL_TO = "EMAIL_TO";
public static final String EMAIL_SSL_PROTOCOLS = "EMAIL_SSL_PROTOCOLS";
public static final String EMAIL_START_TLS_ENABLED = "EMAIL_START_TLS_ENABLED";
public static final String EMAIL_SMTP_AUTH_ENABLED = "EMAIL_SMTP_AUTH_ENABLED";
public static final String DB_NAME = "DB_NAME";
public static final String DB_USERNAME = "DB_USERNAME";
public static final String DB_PASSWORD = "DB_PASSWORD";
Expand Down Expand Up @@ -461,6 +463,8 @@ public void export() throws IOException, SQLException, ClassNotFoundException {
.setUsername(properties.getProperty(EMAIL_USERNAME))
.setPassword(properties.getProperty(EMAIL_PASSWORD))
.setSslProtocols(properties.getProperty(EMAIL_SSL_PROTOCOLS, "TLSv1.2"))
.setStartTlsEnabled(properties.getProperty(EMAIL_START_TLS_ENABLED, "true"))
.setSmtpAuthEnabled(Boolean.parseBoolean(properties.getProperty(EMAIL_SMTP_AUTH_ENABLED, "true")))
.setSubject(properties.getProperty(EMAIL_SUBJECT, sqlFileName.replace(".sql", "").toUpperCase()))
.setMessage(properties.getProperty(EMAIL_MESSAGE, "Please find attached database backup of " + database))
.setAttachments(new File[]{new File(zipFileName)})
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/smattme/MysqlBackup4JIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ void givenDBCredentialsAndEmailConfig_whenExportDatabase_thenBackUpAndMailDbSucc
properties.setProperty(MysqlExportService.EMAIL_FROM, "[email protected]");
properties.setProperty(MysqlExportService.EMAIL_TO, "[email protected]");
properties.setProperty(MysqlExportService.EMAIL_SSL_PROTOCOLS, "TLSv1.2");
properties.setProperty(MysqlExportService.EMAIL_SMTP_AUTH_ENABLED, "true");
properties.setProperty(MysqlExportService.EMAIL_START_TLS_ENABLED, "true");

MysqlExportService mysqlExportService = new MysqlExportService(properties);
mysqlExportService.export();
Expand Down

0 comments on commit 52b4d9a

Please sign in to comment.