Sending mail using the @Configuration annotation
We shall demonstrate here how we can send mail using the Spring mail API.
- First, we provide all the SMTP details in the
.properties
file and read it to the class file with the@Configuration
annotation. The name of the class isMailConfiguration
.mail.properties
file contents are shown below:mail.protocol=smtp mail.host=localhost mail.port=25 mail.smtp.auth=false mail.smtp.starttls.enable=false mail.from=me@localhost mail.username= mail.password= @Configuration @PropertySource("classpath:mail.properties") public class MailConfiguration { @Value("${mail.protocol}") private String protocol; @Value("${mail.host}") private String host; @Value("${mail.port}") private int port; @Value("${mail.smtp.auth}") private boolean auth; @Value("${mail.smtp.starttls.enable}") private boolean starttls; @Value("${mail.from}") private String from; @Value("${mail...