Search in sources :

Example 1 with EmailServerProfile

use of password.pwm.config.profile.EmailServerProfile in project pwm by pwm-project.

the class EmailServerUtil method makeEmailServersMap.

static List<EmailServer> makeEmailServersMap(final Configuration configuration) {
    final List<EmailServer> returnObj = new ArrayList<>();
    final Collection<EmailServerProfile> profiles = configuration.getEmailServerProfiles().values();
    for (final EmailServerProfile profile : profiles) {
        final String id = profile.getIdentifier();
        final String address = profile.readSettingAsString(PwmSetting.EMAIL_SERVER_ADDRESS);
        final int port = (int) profile.readSettingAsLong(PwmSetting.EMAIL_SERVER_PORT);
        final String username = profile.readSettingAsString(PwmSetting.EMAIL_USERNAME);
        final PasswordData password = profile.readSettingAsPassword(PwmSetting.EMAIL_PASSWORD);
        if (!StringUtil.isEmpty(address) && port > 0) {
            final Properties properties = makeJavaMailProps(configuration, address, port);
            final javax.mail.Session session = javax.mail.Session.getInstance(properties, null);
            final EmailServer emailServer = EmailServer.builder().id(id).host(address).port(port).username(username).password(password).javaMailProps(properties).session(session).build();
            returnObj.add(emailServer);
        } else {
            LOGGER.warn("discarding incompletely configured email address for smtp server profile " + id);
        }
    }
    return returnObj;
}
Also used : EmailServerProfile(password.pwm.config.profile.EmailServerProfile) PasswordData(password.pwm.util.PasswordData) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Aggregations

ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 EmailServerProfile (password.pwm.config.profile.EmailServerProfile)1 PasswordData (password.pwm.util.PasswordData)1