![JAR search and dependency download from the Maven repository](/logo.png)
br.com.jhonsapp.email.session.configurator.ServerConfigurator 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.session.configurator;
import java.io.Serializable;
import java.nio.file.FileSystemNotFoundException;
import java.util.Properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.outjected.email.impl.SimpleMailConfig;
import br.com.jhonsapp.email.session.properties.ServerProperties;
import br.com.jhonsapp.email.session.properties.UserProperties;
import br.com.jhonsapp.util.loader.PropertiesLoader;
/**
* This class is used to configure and load information for the mail server.
*
* @author Jhonathan Camacho
*
*/
@Component
public class ServerConfigurator implements Serializable {
/**
* Generated serial version id created at 08 July 2017.
*/
private static final long serialVersionUID = 6009806907368702289L;
@Autowired
private PropertiesLoader loader;
private SimpleMailConfig simpleMailConfig;
private Properties serverInformation;
public void configure(SimpleMailConfig sessionConfig) {
this.simpleMailConfig = sessionConfig;
serverInformation = getServerInformation();
verifyIfAllServerInformationValuesExist();
setServerInformationInSimpleMailConfig();
}
private void verifyIfAllServerInformationValuesExist() {
loader.verifyIfValueExists(serverInformation, ServerProperties.hostKey);
loader.verifyIfValueExists(serverInformation, ServerProperties.portKey);
loader.verifyIfValueExists(serverInformation, ServerProperties.sslKey);
loader.verifyIfValueExists(serverInformation, ServerProperties.authKey);
}
private void setServerInformationInSimpleMailConfig() {
simpleMailConfig.setServerHost(loader.getProperty(serverInformation, ServerProperties.hostKey));
simpleMailConfig
.setServerPort(Integer.parseInt(loader.getProperty(serverInformation, ServerProperties.portKey)));
simpleMailConfig
.setEnableSsl(Boolean.parseBoolean(loader.getProperty(serverInformation, ServerProperties.sslKey)));
simpleMailConfig.setAuth(Boolean.parseBoolean(loader.getProperty(serverInformation, ServerProperties.authKey)));
}
private Properties getServerInformation() {
Properties userProperties = loader.getPropertiesFile(UserProperties.USER_PROPERTIES);
if (serverInformation == null) {
if (typeIsEquals(userProperties, UserProperties.GMAIL)) {
serverInformation = loader.getPropertiesFile(ServerProperties.SERVER_PROPERTIES_GMAIL);
} else if (typeIsEquals(userProperties, UserProperties.HOTMAIL)) {
serverInformation = loader.getPropertiesFile(ServerProperties.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, UserProperties.typeKey).equalsIgnoreCase(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy