SHARE
TWEET

Untitled

a guest Jun 18th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ru.dev.messanger.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.host}")
  14.     private String host;
  15.  
  16.     @Value("${spring.mail.username}")
  17.     private String username;
  18.  
  19.     @Value("${spring.mail.password}")
  20.     private String password;
  21.  
  22.     @Value("${spring.mail.port}")
  23.     private int port;
  24.  
  25.     @Value("${spring.mail.protocol}")
  26.     private String protocol;
  27.  
  28.     @Value("${mail.debug}")
  29.     private String debug;
  30.  
  31.     @Bean
  32.     public JavaMailSender getMailSender() {
  33.         JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
  34.  
  35.         mailSender.setHost(host);
  36.         mailSender.setPort(port);
  37.         mailSender.setUsername(username);
  38.         mailSender.setPassword(password);
  39.  
  40.         Properties properties = mailSender.getJavaMailProperties();
  41.  
  42.         properties.setProperty("mail.transport.protocol", protocol);
  43.         properties.setProperty("mail.debug", debug);
  44.         properties.put("mail.smtp.auth", "true");
  45.         properties.put("mail.smtp.starttls.enable", "true");
  46.         properties.put("mail.smtp.ssl.trust", "smtp.yandex.ru");
  47.  
  48.         return mailSender;
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top