use of org.springframework.mail.javamail.JavaMailSenderImpl in project mica2 by obiba.
the class MailConfiguration method javaMailSender.
@Bean
public JavaMailSenderImpl javaMailSender() {
log.debug("Configuring mail server");
String host = propertyResolver.getProperty(PROP_HOST, DEFAULT_PROP_HOST);
int port = propertyResolver.getProperty(PROP_PORT, Integer.class, 0);
String user = propertyResolver.getProperty(PROP_USER);
String password = propertyResolver.getProperty(PROP_PASSWORD);
String protocol = propertyResolver.getProperty(PROP_PROTO);
Boolean tls = propertyResolver.getProperty(PROP_TLS, Boolean.class, false);
Boolean auth = propertyResolver.getProperty(PROP_AUTH, Boolean.class, false);
JavaMailSenderImpl sender = new JavaMailSenderImpl();
if (host != null && !host.isEmpty()) {
sender.setHost(host);
} else {
log.warn("Warning! Your SMTP server is not configured. We will try to use one on localhost.");
log.debug("Did you configure your SMTP settings in your application.yml?");
sender.setHost(DEFAULT_HOST);
}
sender.setPort(port);
sender.setUsername(user);
sender.setPassword(password);
Properties sendProperties = new Properties();
sendProperties.setProperty(PROP_SMTP_AUTH, auth.toString());
sendProperties.setProperty(PROP_STARTTLS, tls.toString());
sendProperties.setProperty(PROP_TRANSPORT_PROTO, protocol);
sender.setJavaMailProperties(sendProperties);
return sender;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project webapp by elimu-ai.
the class Mailer method sendPlainText.
public static void sendPlainText(String to, String cc, String from, String subject, String text) {
logger.info("sendPlainText");
if (to.contains(",")) {
to = to.replace(",", "");
}
if (to.contains(":")) {
to = to.replace(":", "");
}
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setTo(to);
if (StringUtils.isNotBlank(cc)) {
simpleMailMessage.setCc(cc);
}
simpleMailMessage.setBcc(ADMIN_EMAIL);
simpleMailMessage.setFrom(from);
simpleMailMessage.setSubject(subject);
simpleMailMessage.setText(text);
JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl();
String smtpHost = ConfigHelper.getProperty("smtp.host");
javaMailSenderImpl.setHost(smtpHost);
logger.info("Sending e-mail to " + simpleMailMessage.getTo()[0] + " with subject \"" + simpleMailMessage.getSubject() + "\"...");
logger.info("Text: " + simpleMailMessage.getText());
if (EnvironmentContextLoaderListener.env != Environment.DEV) {
javaMailSenderImpl.send(simpleMailMessage);
}
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project kylo by Teradata.
the class EmailServiceLevelAgreementSpringConfiguration method javaMailSender.
@Bean(name = "slaEmailSender")
public JavaMailSender javaMailSender(@Qualifier("slaEmailConfiguration") EmailConfiguration emailConfiguration) {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
Properties mailProperties = mailSender.getJavaMailProperties();
mailProperties.put("mail.smtp.auth", StringUtils.defaultIfBlank(emailConfiguration.getSmtpAuth(), "false"));
mailProperties.put("mail.smtp.starttls.enable", StringUtils.defaultIfBlank(emailConfiguration.getStarttls(), "false"));
if (StringUtils.isNotBlank(emailConfiguration.getStarttlsRequired())) {
mailProperties.put("mail.smtp.starttls.required", emailConfiguration.getStarttlsRequired());
}
if (StringUtils.isNotBlank(emailConfiguration.getSmptAuthNtmlDomain())) {
mailProperties.put("mail.smtp.auth.ntlm.domain", emailConfiguration.getSmptAuthNtmlDomain());
}
mailProperties.put("mail.smtp.connectiontimeout", StringUtils.defaultIfBlank(emailConfiguration.getSmtpConnectionTimeout(), "5000"));
mailProperties.put("mail.smtp.timeout", StringUtils.defaultIfBlank(emailConfiguration.getSmtpTimeout(), "5000"));
mailProperties.put("mail.smtp.writetimeout", StringUtils.defaultIfBlank(emailConfiguration.getSmtpWriteTimeout(), "5000"));
if (StringUtils.isNotBlank(emailConfiguration.getSslEnable())) {
mailProperties.put("mail.smtp.ssl.enable", emailConfiguration.getSslEnable());
}
if (StringUtils.isNotBlank(emailConfiguration.getDebug())) {
mailProperties.put("mail.debug", emailConfiguration.getDebug());
}
mailSender.setHost(emailConfiguration.getHost());
mailSender.setPort(emailConfiguration.getPort());
mailSender.setProtocol(emailConfiguration.getProtocol());
mailSender.setUsername(emailConfiguration.getUsername());
mailSender.setPassword(emailConfiguration.getPassword());
return mailSender;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project lumberjack by fn-ctional.
the class SpringConfiguration method getJavaMailSender.
@Bean
public JavaMailSender getJavaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(this.host);
mailSender.setPort(this.port);
mailSender.setUsername(this.username);
mailSender.setPassword(this.password);
Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.debug", "false");
return mailSender;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project fake-smtp-server by gessnerfl.
the class TestDataCreator method getEmailSender.
private static JavaMailSender getEmailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("localhost");
mailSender.setPort(5025);
Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "false");
props.put("mail.smtp.starttls.enable", "false");
props.put("mail.debug", "false");
return mailSender;
}
Aggregations