Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. import org.springframework.beans.factory.annotation.Autowired;
  2. import org.springframework.boot.context.properties.ConfigurationProperties;
  3. import org.springframework.boot.context.properties.EnableConfigurationProperties;
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.context.annotation.Configuration;
  6. import org.springframework.mail.SimpleMailMessage;
  7.  
  8. @EnableConfigurationProperties
  9. public class MailSender
  10. {
  11. @Autowired
  12. private static JavaMailSender mailSender;
  13.  
  14. public static void main(String[] args)
  15. {
  16. send();
  17. }
  18. public static void send() {
  19. SimpleMailMessage message = new SimpleMailMessage();
  20. message.setFrom("abc@gmail.com");
  21. message.setTo("xyz@gmail.com");
  22. message.setSubject("hello");
  23. mailSender.send();
  24. }
  25. }
  26.  
  27. <?xml version="1.0" encoding="UTF-8"?>
  28. <project xmlns="http://maven.apache.org/POM/4.0.0"
  29. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  30. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  31. <modelVersion>4.0.0</modelVersion>
  32.  
  33. <groupId>Example</groupId>
  34. <artifactId>SendingEmail</artifactId>
  35. <version>1.0-SNAPSHOT</version>
  36. <parent>
  37. <groupId>org.springframework.boot</groupId>
  38. <artifactId>spring-boot-starter-parent</artifactId>
  39. <version>1.3.2.RELEASE</version>
  40. </parent>
  41.  
  42. <dependencies>
  43. <dependency>
  44. <groupId>org.springframework.boot</groupId>
  45. <artifactId>spring-boot-starter-web</artifactId>
  46. </dependency>
  47.  
  48. <dependency>
  49. <groupId>org.springframework.boot</groupId>
  50. <artifactId>spring-boot-starter-mail</artifactId>
  51. </dependency>
  52.  
  53. <dependency>
  54. <groupId>javax.mail</groupId>
  55. <artifactId>mail</artifactId>
  56. <version>1.4.5</version>
  57. </dependency>
  58. </dependencies>
  59.  
  60.  
  61. </project>
  62.  
  63. spring.mail.host=smtp.gmail.com
  64. spring.mail.username=*****
  65. spring.mail.password=*****
  66. spring.mail.properties.mail.smtp.auth = true
  67. spring.mail.properties.mail.smtp.socketFactory.port = 25
  68. spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
  69. spring.mail.properties.mail.smtp.socketFactory.fallback = false
  70. spring.mail.properties.mail.smtp.ssl.enable=true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement