Merge pull request #3649 from josefhernandez/master
* pr/3649: Polish Customize mail sender protocol
This commit is contained in:
commit
d9f6238a33
|
|
@ -55,6 +55,11 @@ public class MailProperties {
|
|||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* Protocol used by the SMTP server.
|
||||
*/
|
||||
private String protocol = "smtp";
|
||||
|
||||
/**
|
||||
* Default MimeMessage encoding.
|
||||
*/
|
||||
|
|
@ -107,6 +112,14 @@ public class MailProperties {
|
|||
this.password = password;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return this.protocol;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public Charset getDefaultEncoding() {
|
||||
return this.defaultEncoding;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.mail;
|
|||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.activation.MimeType;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
|
@ -79,6 +78,7 @@ public class MailSenderAutoConfiguration {
|
|||
}
|
||||
sender.setUsername(this.properties.getUsername());
|
||||
sender.setPassword(this.properties.getPassword());
|
||||
sender.setProtocol(this.properties.getProtocol());
|
||||
if (this.properties.getDefaultEncoding() != null) {
|
||||
sender.setDefaultEncoding(this.properties.getDefaultEncoding().name());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,14 +100,16 @@ public class MailSenderAutoConfigurationTests {
|
|||
JavaMailSenderImpl bean = (JavaMailSenderImpl) this.context
|
||||
.getBean(JavaMailSender.class);
|
||||
assertEquals(host, bean.getHost());
|
||||
assertEquals(JavaMailSenderImpl.DEFAULT_PORT, bean.getPort());
|
||||
assertEquals(JavaMailSenderImpl.DEFAULT_PROTOCOL, bean.getProtocol());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smptHostWithSettings() {
|
||||
public void smtpHostWithSettings() {
|
||||
String host = "192.168.1.234";
|
||||
load(EmptyConfig.class, "spring.mail.host:" + host, "spring.mail.port:42",
|
||||
"spring.mail.username:john", "spring.mail.password:secret",
|
||||
"spring.mail.default-encoding:US-ASCII");
|
||||
"spring.mail.default-encoding:US-ASCII", "spring.mail.protocol:smtps");
|
||||
JavaMailSenderImpl bean = (JavaMailSenderImpl) this.context
|
||||
.getBean(JavaMailSender.class);
|
||||
assertEquals(host, bean.getHost());
|
||||
|
|
@ -115,6 +117,7 @@ public class MailSenderAutoConfigurationTests {
|
|||
assertEquals("john", bean.getUsername());
|
||||
assertEquals("secret", bean.getPassword());
|
||||
assertEquals("US-ASCII", bean.getDefaultEncoding());
|
||||
assertEquals("smtps", bean.getProtocol());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -548,6 +548,7 @@ content into your application; rather pick only the properties that you need.
|
|||
# Email ({sc-spring-boot-autoconfigure}/mail/MailProperties.{sc-ext}[MailProperties])
|
||||
spring.mail.host=smtp.acme.org # mail server host
|
||||
spring.mail.port= # mail server port
|
||||
spring.mail.protocol=smtp # mail server protocol
|
||||
spring.mail.username=
|
||||
spring.mail.password=
|
||||
spring.mail.default-encoding=UTF-8 # encoding to use for MimeMessages
|
||||
|
|
|
|||
Loading…
Reference in New Issue