Java Mail API: Difference between revisions
Jump to navigation
Jump to search
m (Shahed moved page Java Mail Api to Java Mail API) |
No edit summary |
||
Line 1: | Line 1: | ||
==Mail Config== | |||
<source lang="java"> | |||
import java.util.Properties; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.context.annotation.Bean; | |||
import org.springframework.context.annotation.Configuration; | |||
import org.springframework.mail.javamail.JavaMailSender; | |||
import org.springframework.mail.javamail.JavaMailSenderImpl; | |||
@Configuration | |||
public class MailConfig { | |||
@Bean | |||
public JavaMailSender getMailSender() { | |||
JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); | |||
mailSender.setHost("mail.chorke.org"); | |||
mailSender.setPort(465); | |||
if(!"[email protected]".isEmpty()) { | |||
mailSender.setUsername("[email protected]"); | |||
mailSender.setPassword("p@$$w0rd"); | |||
} | |||
Properties javaMailProperties = new Properties(); | |||
javaMailProperties.put("mail.smtp.auth", "[email protected]".isEmpty() ? "false" : "true"); | |||
javaMailProperties.put("mail.smtp.ssl.trust", "mail.chorke.org"); | |||
javaMailProperties.put("mail.smtp.starttls.enable", "true"); | |||
javaMailProperties.put("mail.transport.protocol", "smtp"); | |||
javaMailProperties.put("mail.smtp.ssl.enable", "true"); | |||
javaMailProperties.put("mail.smtp.ehlo", true); | |||
javaMailProperties.put("mail.debug", "true"); | |||
mailSender.setJavaMailProperties(javaMailProperties); | |||
return mailSender; | |||
} | |||
} | |||
</source> | |||
==References== | ==References== | ||
{| | {| |
Revision as of 09:37, 25 March 2022
Mail Config
import java.util.Properties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
@Configuration
public class MailConfig {
@Bean
public JavaMailSender getMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("mail.chorke.org");
mailSender.setPort(465);
if(!"[email protected]".isEmpty()) {
mailSender.setUsername("[email protected]");
mailSender.setPassword("p@$$w0rd");
}
Properties javaMailProperties = new Properties();
javaMailProperties.put("mail.smtp.auth", "[email protected]".isEmpty() ? "false" : "true");
javaMailProperties.put("mail.smtp.ssl.trust", "mail.chorke.org");
javaMailProperties.put("mail.smtp.starttls.enable", "true");
javaMailProperties.put("mail.transport.protocol", "smtp");
javaMailProperties.put("mail.smtp.ssl.enable", "true");
javaMailProperties.put("mail.smtp.ehlo", true);
javaMailProperties.put("mail.debug", "true");
mailSender.setJavaMailProperties(javaMailProperties);
return mailSender;
}
}