Skip to content

Commit

Permalink
smpt
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Dec 28, 2023
1 parent 2c09423 commit f4894c9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
package net.dancier.kikeriki.adapter.out.mail;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

@Configuration
public class MailSenderConfiguration {

@Bean
@Profile({"dev"})
public JavaMailSender getJavaMailSender() {
JavaMailSender javaMailSender = new DumpingMailSender();
return javaMailSender;
}

@Profile("staging")
public JavaMailSender getRealSender(
@Value("${app.mail.host}") String hostname,
@Value("${app.mail.port}") String port,
@Value("${app.mail.user}") String user,
@Value("${app.mail.pass}") String pass
) {
JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
javaMailSender.setHost(hostname);
javaMailSender.setPort(Integer.valueOf(port));

javaMailSender.setUsername(user);
javaMailSender.setPassword(pass);

Properties props = javaMailSender.getJavaMailProperties();
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.debug", "true");

return javaMailSender;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
spring:
profiles:
active: dev
datasource:
url: jdbc:postgresql://localhost:5432/kikeriki
username: kikeriki
Expand Down

0 comments on commit f4894c9

Please sign in to comment.