List of usage examples for org.springframework.mail.javamail JavaMailSenderImpl getUsername
@Nullable
public String getUsername()
From source file:com.formkiq.core.service.notification.MailSenderServiceTest.java
/** * testAfterPropertiesSet01().//from w w w . j av a 2s .co m * expect JavaMailSenderImpl * @throws Exception Exception */ @Test public void testAfterPropertiesSet01() throws Exception { // given final int port = 587; String data = "mail.host=smtp.gmail.com\n" + "mail.port=" + port + "\n" + "mail.username=test\n" + "mail.password=pass\n" + "mail.smtp.auth=true\n" + "mail.smtp.auth=true\n" + "mail.smtp.starttls.enable=true\n" + "mail.smtp.quitwait=false"; InputStream is = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)); MailSenderService ms = new MailSenderService(); // when ms.afterPropertiesSet(is); // then assertTrue(ms.getMailSender() instanceof JavaMailSenderImpl); JavaMailSenderImpl js = (JavaMailSenderImpl) ms.getMailSender(); assertEquals("smtp.gmail.com", js.getHost()); assertEquals(port, js.getPort()); assertEquals("test", js.getUsername()); assertEquals("true", js.getJavaMailProperties().getProperty("mail.smtp.starttls.enable")); assertEquals("false", js.getJavaMailProperties().getProperty("mail.smtp.quitwait")); assertEquals("true", js.getJavaMailProperties().getProperty("mail.smtp.auth")); }
From source file:com.github.dactiv.fear.service.service.message.MessageService.java
/** * ???/*from w w w .ja va 2 s.co m*/ * * @param nickname * @param javaMailSender ?? * * @return ?? */ private String getSendForm(String nickname, JavaMailSender javaMailSender) { JavaMailSenderImpl impl = null; if (javaMailSender instanceof JavaMailSenderImpl) { impl = (JavaMailSenderImpl) javaMailSender; } if (impl == null) { throw new ServiceException( JavaMailSenderImpl.class + " ?? " + javaMailSender.getClass() + ""); } String address; String propertiesNickname = impl.getJavaMailProperties().getProperty("mail.nickname", nickname); try { if (StringUtils.isEmpty(propertiesNickname)) { address = impl.getUsername(); } else { address = MimeUtility.encodeText(propertiesNickname) + " <" + impl.getUsername() + ">"; } } catch (UnsupportedEncodingException e) { LOGGER.warn("?[" + nickname + "],?" + impl.getUsername() + "", e); address = impl.getUsername(); } return address; }
From source file:com.formkiq.core.service.notification.MailSenderService.java
/** * @param prop {@link Properties}/*from ww w . j a v a2 s. co m*/ * @return {@link JavaMailSenderImpl} * @throws IOException IOException */ private JavaMailSenderImpl createJavaMailSender(final Properties prop) throws IOException { JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost(prop.getProperty("mail.host")); sender.setPort(Integer.parseInt(prop.getProperty("mail.port"))); sender.setUsername(prop.getProperty("mail.username")); sender.setPassword(prop.getProperty("mail.password")); Properties property = sender.getJavaMailProperties(); if (prop.containsKey("mail.smtp.auth")) { property.setProperty("mail.smtp.auth", prop.getProperty("mail.smtp.auth")); } if (prop.containsKey("mail.smtp.starttls.enable")) { property.setProperty("mail.smtp.starttls.enable", prop.getProperty("mail.smtp.starttls.enable")); } if (prop.containsKey("mail.smtp.quitwait")) { property.setProperty("mail.smtp.quitwait", prop.getProperty("mail.smtp.quitwait")); } LOG.log(Level.INFO, "Setting mail.host = " + sender.getHost() + ":" + sender.getPort()); LOG.log(Level.INFO, "Setting mail.username = " + sender.getUsername()); for (Map.Entry<Object, Object> e : sender.getJavaMailProperties().entrySet()) { LOG.log(Level.INFO, "Setting " + e.getKey() + " = " + e.getValue()); } return sender; }
From source file:org.apache.syncope.core.provisioning.java.job.notification.NotificationJobDelegate.java
@Override public void afterPropertiesSet() throws Exception { if (mailSender instanceof JavaMailSenderImpl) { JavaMailSenderImpl javaMailSender = (JavaMailSenderImpl) mailSender; Properties javaMailProperties = javaMailSender.getJavaMailProperties(); Properties props = PropertyUtils.read(Encryptor.class, "mail.properties", "conf.directory").getLeft(); for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) { String prop = (String) e.nextElement(); if (prop.startsWith("mail.smtp.")) { javaMailProperties.setProperty(prop, props.getProperty(prop)); }/*from ww w.jav a2s . co m*/ } if (StringUtils.isNotBlank(javaMailSender.getUsername())) { javaMailProperties.setProperty("mail.smtp.auth", "true"); } javaMailSender.setJavaMailProperties(javaMailProperties); String mailDebug = props.getProperty("mail.debug", "false"); if (BooleanUtils.toBoolean(mailDebug)) { Session session = javaMailSender.getSession(); session.setDebug(true); session.setDebugOut(new PrintStream(new LogOutputStream(LOG))); } } }