setPort(MailUtils.getDefaultPortForProtocol(uri.getScheme()));
}
}
protected JavaMailSenderImpl createJavaMailSender() {
JavaMailSenderImpl answer = new JavaMailSenderImpl();
if (javaMailProperties != null) {
answer.setJavaMailProperties(javaMailProperties);
} else {
// set default properties if none provided
answer.setJavaMailProperties(createJavaMailProperties());
// add additional properties if provided
if (additionalJavaMailProperties != null) {
answer.getJavaMailProperties().putAll(additionalJavaMailProperties);
}
}
if (defaultEncoding != null) {
answer.setDefaultEncoding(defaultEncoding);
}
if (host != null) {
answer.setHost(host);
}
if (port >= 0) {
answer.setPort(port);
}
if (username != null) {
answer.setUsername(username);
}
if (password != null) {
answer.setPassword(password);
}
if (protocol != null) {
answer.setProtocol(protocol);
}
if (session != null) {
answer.setSession(session);
} else {
// use our authenticator that does no live user interaction but returns the already configured username and password
Session session = Session.getInstance(answer.getJavaMailProperties(), getAuthenticator());
// sets the debug mode of the underlying mail framework
session.setDebug(debugMode);
answer.setSession(session);
}
return answer;
}