Reputation: 11
I want to send mail to reset password for users if he forgot his password i get this error:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.NoSuchProviderException: No provider for ${mail.protocol}. Failed messages: javax.mail.NoSuchProviderException: No provider for ${mail.protocol}; message exception details (1) are:
and this is my MailConfiguration.java
;
public class MailConfiguration {
@Value("${mail.protocol}")
private String protocol;
@Value("${mail.host}")
private String host;
@Value("${mail.from}")
private String from;
@Value("${mail.username}")
private String username;
@Value("${mail.password}")
private String password;
@Bean
public JavaMailSender javaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
Properties mailProperties = new Properties();
mailProperties.put(false, auth);
mailProperties.put(false, starttls);
mailSender.setJavaMailProperties(mailProperties);
mailSender.setHost(host);
mailSender.setPort(465);
mailSender.setProtocol(protocol);
mailSender.setUsername(username);
mailSender.setPassword(password);
return mailSender;
}
}
this is my EmailConfig.properties:
mail.protocol=smtp
mail.host=localhost
mail.port=465
mail.smtp.auth=false
mail.smtp.starttls.enable=false
mail.from=me@localhost
mail.username=
mail.password=
any help Thanks in advance.
Upvotes: 0
Views: 1203
Reputation: 111
It seems, that you have not properly connected your EmailConfig.properties, because mailProtocol is not read from it.
Make sure you have @PropertySource somewhere in your config classes with valid path to your properties file(i.e. "classpath:EmailConfig.properties")
Upvotes: 1