use of org.springframework.mail.javamail.JavaMailSenderImpl in project spring-boot by spring-projects.
the class MailSenderAutoConfigurationTests method defaultEncodingWithJndi.
@Test
void defaultEncodingWithJndi() {
configureJndiSession("foo");
this.contextRunner.withPropertyValues("spring.mail.jndi-name:foo", "spring.mail.default-encoding:UTF-16").run((context) -> {
assertThat(context).hasSingleBean(JavaMailSenderImpl.class);
JavaMailSenderImpl mailSender = context.getBean(JavaMailSenderImpl.class);
assertThat(mailSender.getDefaultEncoding()).isEqualTo("UTF-16");
});
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project spring-boot by spring-projects.
the class MailSenderJndiConfiguration method mailSender.
@Bean
JavaMailSenderImpl mailSender(Session session) {
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setDefaultEncoding(this.properties.getDefaultEncoding().name());
sender.setSession(session);
return sender;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project spring-boot by spring-projects.
the class MailSenderPropertiesConfiguration method mailSender.
@Bean
@ConditionalOnMissingBean(JavaMailSender.class)
JavaMailSenderImpl mailSender(MailProperties properties) {
JavaMailSenderImpl sender = new JavaMailSenderImpl();
applyProperties(properties, sender);
return sender;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project OpenClinica by OpenClinica.
the class SecureController method sendEmail.
public Boolean sendEmail(String to, String from, String subject, String body, Boolean htmlEmail, String successMessage, String failMessage, Boolean sendMessage) throws Exception {
Boolean messageSent = true;
try {
JavaMailSenderImpl mailSender = (JavaMailSenderImpl) SpringServletAccess.getApplicationContext(context).getBean("mailSender");
// @pgawade 09-Feb-2012 #issue 13201 - setting the "mail.smtp.localhost" property to localhost when java API is not able to
// retrieve the host name
Properties javaMailProperties = mailSender.getJavaMailProperties();
if (null != javaMailProperties) {
if (javaMailProperties.get("mail.smtp.localhost") == null || ((String) javaMailProperties.get("mail.smtp.localhost")).equalsIgnoreCase("")) {
javaMailProperties.put("mail.smtp.localhost", "localhost");
}
}
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, htmlEmail);
helper.setFrom(from);
helper.setTo(processMultipleImailAddresses(to.trim()));
helper.setSubject(subject);
helper.setText(body, true);
mailSender.send(mimeMessage);
if (successMessage != null && sendMessage) {
addPageMessage(successMessage);
}
logger.debug("Email sent successfully on {}", new Date());
} catch (MailException me) {
me.printStackTrace();
if (failMessage != null && sendMessage) {
addPageMessage(failMessage);
}
logger.debug("Email could not be sent on {} due to: {}", new Date(), me.toString());
messageSent = false;
}
return messageSent;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project waltz by khartec.
the class DIConfiguration method mailSender.
@Bean
public JavaMailSender mailSender() {
if (smtpHost == null) {
return new DummyJavaMailSender();
} else {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(smtpHost);
mailSender.setPort(smtpPort);
return mailSender;
}
}
Aggregations