|
| 1 | +package com.zenfulcode.commercify.commercify.config; |
| 2 | + |
| 3 | +import org.springframework.beans.factory.annotation.Value; |
| 4 | +import org.springframework.context.annotation.Bean; |
| 5 | +import org.springframework.context.annotation.Configuration; |
| 6 | +import org.springframework.mail.javamail.JavaMailSender; |
| 7 | +import org.springframework.mail.javamail.JavaMailSenderImpl; |
| 8 | + |
| 9 | +import java.util.Properties; |
| 10 | + |
| 11 | +@Configuration |
| 12 | +public class MailConfig { |
| 13 | + @Value("${spring.mail.username}") |
| 14 | + private String username; |
| 15 | + @Value("${spring.mail.password}") |
| 16 | + private String password; |
| 17 | + @Value("${spring.mail.host}") |
| 18 | + private String host; |
| 19 | + @Value("${spring.mail.port}") |
| 20 | + private int port; |
| 21 | + |
| 22 | + @Value("${spring.mail.properties.mail.smtp.starttls.enable}") |
| 23 | + private boolean tls = true; |
| 24 | + @Value("${spring.mail.properties.mail.smtp.auth}") |
| 25 | + private boolean auth = true; |
| 26 | + |
| 27 | + @Bean |
| 28 | + public JavaMailSender getJavaMailSender() { |
| 29 | + JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); |
| 30 | + mailSender.setHost(host); |
| 31 | + mailSender.setPort(port); |
| 32 | + |
| 33 | + mailSender.setUsername(username); |
| 34 | + mailSender.setPassword(password); |
| 35 | + |
| 36 | + Properties props = mailSender.getJavaMailProperties(); |
| 37 | + props.put("mail.transport.protocol", "smtp"); |
| 38 | + props.put("mail.smtp.auth", auth); |
| 39 | + props.put("mail.smtp.starttls.enable", tls); |
| 40 | + props.put("mail.debug", "true"); |
| 41 | + |
| 42 | + return mailSender; |
| 43 | + } |
| 44 | +} |
0 commit comments