br.com.jhonsapp.email.configuration.Information.ConfigureServerInformation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of email-dispatcher Show documentation
Show all versions of email-dispatcher Show documentation
Email Dispatcher is an open source project created by Jhonys Camacho and Jhonathan Camacho to facilitate the sending of emails.
package br.com.jhonsapp.email.configuration.Information;
import java.nio.file.FileSystemNotFoundException;
import java.util.Properties;
import com.outjected.email.impl.SimpleMailConfig;
import br.com.jhonsapp.util.loader.PropertiesLoader;
public class ConfigureServerInformation {
private PropertiesLoader loader = new PropertiesLoader();
private SimpleMailConfig simpleMailConfig;
private Properties serverInformation = null;
public void configure(Properties userProperties, SimpleMailConfig simpleMailConfig) {
this.simpleMailConfig = simpleMailConfig;
serverInformation = getServerInformation(userProperties);
verifyIfAllServerInformationValuesExist();
addServerInformationInSimpleMailConfig();
}
private void verifyIfAllServerInformationValuesExist() {
loader.verifyIfValueExists(serverInformation, PropertiesInformation.hostKey);
loader.verifyIfValueExists(serverInformation, PropertiesInformation.portKey);
loader.verifyIfValueExists(serverInformation, PropertiesInformation.sslKey);
loader.verifyIfValueExists(serverInformation, PropertiesInformation.authKey);
}
private void addServerInformationInSimpleMailConfig() {
simpleMailConfig.setServerHost(loader.getProperty(serverInformation, PropertiesInformation.hostKey));
simpleMailConfig
.setServerPort(Integer.parseInt(loader.getProperty(serverInformation, PropertiesInformation.portKey)));
simpleMailConfig.setEnableSsl(
Boolean.parseBoolean(loader.getProperty(serverInformation, PropertiesInformation.sslKey)));
simpleMailConfig
.setAuth(Boolean.parseBoolean(loader.getProperty(serverInformation, PropertiesInformation.authKey)));
}
private Properties getServerInformation(Properties userProperties) {
if (serverInformation == null) {
if (typeIsEquals(userProperties, PropertiesInformation.GMAIL)) {
serverInformation = loader.getPropertiesFile(PropertiesInformation.SERVER_PROPERTIES_GMAIL);
} else if (typeIsEquals(userProperties, PropertiesInformation.HOTMAIL)) {
serverInformation = loader.getPropertiesFile(PropertiesInformation.SERVER_PROPERTIES_HOTMAIL);
} else {
throw new FileSystemNotFoundException("This informed email provider is not supported.");
}
}
return serverInformation;
}
private boolean typeIsEquals(Properties userProperties, String value) {
return loader.getProperty(userProperties, PropertiesInformation.typeKey).equalsIgnoreCase(value);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy