Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.context.properties.ConfigurationProperties;
- import org.springframework.boot.context.properties.EnableConfigurationProperties;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.mail.SimpleMailMessage;
- @EnableConfigurationProperties
- public class MailSender
- {
- @Autowired
- private static JavaMailSender mailSender;
- public static void main(String[] args)
- {
- send();
- }
- public static void send() {
- SimpleMailMessage message = new SimpleMailMessage();
- message.setFrom("abc@gmail.com");
- message.setTo("xyz@gmail.com");
- message.setSubject("hello");
- mailSender.send();
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>Example</groupId>
- <artifactId>SendingEmail</artifactId>
- <version>1.0-SNAPSHOT</version>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.3.2.RELEASE</version>
- </parent>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-mail</artifactId>
- </dependency>
- <dependency>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- <version>1.4.5</version>
- </dependency>
- </dependencies>
- </project>
- spring.mail.host=smtp.gmail.com
- spring.mail.username=*****
- spring.mail.password=*****
- spring.mail.properties.mail.smtp.auth = true
- spring.mail.properties.mail.smtp.socketFactory.port = 25
- spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
- spring.mail.properties.mail.smtp.socketFactory.fallback = false
- spring.mail.properties.mail.smtp.ssl.enable=true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement