use of org.springframework.mail.javamail.JavaMailSenderImpl in project cia by Hack23.
the class EmailServiceImpl method getMailSender.
/**
* Gets the mail sender.
*
* @return the mail sender
*/
private JavaMailSender getMailSender() {
final JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
final ApplicationConfiguration smtpHostConfig = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_HOST, SMTP_HOST, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_HOST, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_HOST, "localhost");
final ApplicationConfiguration smtpPort = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_PORT, SMTP_PORT, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_PORT, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_PORT, "587");
final ApplicationConfiguration smtpUsername = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_USERNAME, SMTP_USERNAME, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_USERNAME, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_USERNAME, "username");
final ApplicationConfiguration smtpPassword = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_SECRET, SMTP_SECRET, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_SECRET, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_SECRET, "password");
final ApplicationConfiguration smtpAuth = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_AUTH, SMTP_AUTH, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_AUTH, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_AUTH, "true");
final ApplicationConfiguration smtpStartTlsEnable = applicationConfigurationService.checkValueOrLoadDefault(EMAIL_CONFIGURATION_SMTP_STARTTLS_ENABLE, SMTP_STARTTLS_ENABLE, ConfigurationGroup.EXTERNAL_SERVICES, EmailServiceImpl.class.getSimpleName(), SMTP_STARTTLS_ENABLE, RESPONSIBLE_FOR_SENDING_EMAIL, APPLICATION_EMAIL_SMTP_STARTTLS_ENABLE, "true");
javaMailSender.setHost(smtpHostConfig.getPropertyValue());
javaMailSender.setPort(Integer.parseInt(smtpPort.getPropertyValue()));
javaMailSender.setUsername(smtpUsername.getPropertyValue());
javaMailSender.setPassword(smtpPassword.getPropertyValue());
final Properties javaMailProperties = new Properties();
javaMailProperties.setProperty(MAIL_SMTP_AUTH, smtpAuth.getPropertyValue());
javaMailProperties.setProperty(MAIL_SMTP_STARTTLS_ENABLE, smtpStartTlsEnable.getPropertyValue());
javaMailSender.setJavaMailProperties(javaMailProperties);
return javaMailSender;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project JavaForFun by gumartinm.
the class EmailServiceTest method setUp.
@Before
public void setUp() throws Exception {
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
senderImpl.setPort(3025);
senderImpl.setHost("localhost");
emailService = new EmailServiceImpl(senderImpl);
testSmtp = new GreenMail(ServerSetupTest.SMTP);
testSmtp.start();
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project pmph by BCSquad.
the class JavaMailSenderUtil method sendMail.
/**
* <pre>
* 功能描述:发送邮件
* 使用示范:
*
* @param title 邮件标题
* @param content 邮件标题内容
* @param toMail 收件人
* @return true/false
* @throws Exception
* </pre>
*/
public boolean sendMail(String title, String content, String[] toMail) throws Exception {
Boolean isOk = false;
// 创建邮件发送类
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
// 设置邮件
MimeMessage mailMessage = null;
try {
mailMessage = JavaMailSenderConfig(senderImpl);
// 设置邮件
MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "UTF-8");
// 收件人
messageHelper.setTo(toMail);
// 发件人
messageHelper.setFrom(PropsUtil.getString(properties, "mail.smtp.username"));
// 标题
messageHelper.setSubject(title);
// 内容,true 表示启动HTML格式的邮件
messageHelper.setText(content, true);
// 发送邮件
senderImpl.send(mailMessage);
isOk = true;
logger.info("邮件发送成功...");
} catch (MessagingException e) {
logger.error("邮件发送时发生异常:{}", e.getMessage());
logger.info("邮件进行重发");
try {
Thread.sleep(2000);
senderImpl.send(mailMessage);
isOk = true;
} catch (InterruptedException ie) {
logger.error("重发邮件时发生异常:{}", ie.getMessage());
}
}
return isOk;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project BroadleafCommerce by BroadleafCommerce.
the class AdminSpringBootTestConfiguration method blMailSender.
/**
* A dummy mail sender has been set to send emails for testing purposes only
* To view the emails sent use "DevNull SMTP" (download separately) with the following setting:
* Port: 30000
*/
@Bean
public MailSender blMailSender() {
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost("localhost");
sender.setPort(30000);
sender.setProtocol("smtp");
Properties javaMailProps = new Properties();
javaMailProps.setProperty("mail.smtp.starttls.enable", "true");
javaMailProps.setProperty("mail.smtp.timeout", "25000");
sender.setJavaMailProperties(javaMailProps);
return sender;
}
use of org.springframework.mail.javamail.JavaMailSenderImpl in project cloudbreak by hortonworks.
the class EmailSenderHostServiceTypeTest method before.
@Before
public void before() throws IOException, TemplateException {
greenMail = new GreenMail(new ServerSetup(3465, null, ServerSetup.PROTOCOL_SMTP));
greenMail.setUser("demouser", "demopwd");
greenMail.start();
IdentityUser identityUser = new IdentityUser("sdf", "testuser", "testaccount", new ArrayList<>(), "familyname", "givenName", new Date());
ReflectionTestUtils.setField(emailSenderService, "freemarkerConfiguration", freemarkerConfiguration());
ReflectionTestUtils.setField(emailSenderService, "successClusterMailTemplatePath", "templates/cluster-installer-mail-success.ftl");
ReflectionTestUtils.setField(emailSenderService, "failedClusterMailTemplatePath", "templates/cluster-installer-mail-fail.ftl");
JavaMailSender mailSender = new JavaMailSenderImpl();
((JavaMailSenderImpl) mailSender).setHost("localhost");
((JavaMailSenderImpl) mailSender).setPort(3465);
((JavaMailSenderImpl) mailSender).setUsername("demouser2");
((JavaMailSenderImpl) mailSender).setPassword("demopwd2");
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", false);
props.put("mail.smtp.starttls.enable", false);
props.put("mail.debug", false);
((JavaMailSenderImpl) mailSender).setJavaMailProperties(props);
ReflectionTestUtils.setField(emailSenderService, "mailSender", mailSender);
EmailMimeMessagePreparator mmp = new EmailMimeMessagePreparator();
ReflectionTestUtils.setField(mmp, "msgFrom", "no-reply@hortonworks.com");
ReflectionTestUtils.setField(emailSenderService, "emailMimeMessagePreparator", mmp);
when(userDetailsService.getDetails(anyString(), any(UserFilterField.class))).thenReturn(identityUser);
}
Aggregations