List of usage examples for org.springframework.mail.javamail JavaMailSenderImpl setHost
public void setHost(@Nullable String host)
From source file:com.miserablemind.butter.bootstrap.RootContext.java
/** * E-mail Sender configured using {@link ConfigMail}. * * @return {@link JavaMailSender} bean./* www .j a v a 2s . c om*/ */ @Bean public JavaMailSender emailSender() { ConfigMail configMail = configSystem.getConfigMail(); JavaMailSenderImpl emailSender = new JavaMailSenderImpl(); emailSender.setHost(configMail.getHost()); emailSender.setUsername(configMail.getUsername()); emailSender.setPassword(configMail.getPassword()); emailSender.setPort(configMail.getPort()); Properties props = new Properties(); props.put("mail.smtp.auth", configMail.isSmtpAuth()); props.put("mail.smtp.starttls.enable", configMail.isStartTls()); props.put("mail.transport.protocol", configMail.getProtocol()); props.put("mail.smtp.socketFactory.class", configMail.getSocketFactoryClass()); props.put("mail.smtp.socketFactory.fallback", configMail.isSocketFactoryFallback()); emailSender.setJavaMailProperties(props); return emailSender; }
From source file:com.restfiddle.config.mail.MailConfig.java
@Bean public JavaMailSender javaMailSender() { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); Properties mailProperties = new Properties(); mailSender.setProtocol(env.getProperty("mail.protocol")); mailSender.setHost(env.getProperty("mail.host")); mailSender.setPort(Integer.parseInt(env.getProperty("mail.port"))); mailSender.setUsername(env.getProperty("mail.username")); mailSender.setPassword(env.getProperty("mail.password")); mailProperties.put("mail.smtp.auth", env.getProperty("mail.smtp.auth")); mailProperties.put("mail.smtp.starttls.enable", env.getProperty("mail.smtp.starttls.enable")); mailProperties.put("mail.smtp.debug", env.getProperty("mail.smtp.debug")); mailProperties.put("mail.smtp.socketFactory.port", "465"); mailProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); mailProperties.put("mail.smtps.ssl.trust", env.getProperty("mail.smtps.ssl.trust")); mailProperties.put("mail.smtps.ssl.checkserveridentity", env.getProperty("mail.smtps.ssl.checkserveridentity")); mailSender.setJavaMailProperties(mailProperties); return mailSender; }
From source file:com.mobileman.projecth.TestCaseBase.java
/** * @throws Exception//from w ww . ja va 2 s .co m */ @Before public void setUp() throws Exception { sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory"); try { session = SessionFactoryUtils.getSession(sessionFactory, false); if (session == null) { sessionOwner = true; session = SessionFactoryUtils.getSession(sessionFactory, true); TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); } else { sessionOwner = false; } } catch (IllegalStateException e) { } if (wiser == null) { wiser = new Wiser(); wiser.setPort(2525); wiser.start(); @SuppressWarnings("unchecked") Map<String, JavaMailSenderImpl> ofType = applicationContext .getBeansOfType(org.springframework.mail.javamail.JavaMailSenderImpl.class); for (Entry<String, JavaMailSenderImpl> bean : ofType.entrySet()) { JavaMailSenderImpl mailSender = bean.getValue(); mailSender.setPort(2525); mailSender.setHost("localhost"); mailSender.setUsername(null); mailSender.setPassword(null); Properties props = new Properties(); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.host", "localhost"); props.put("mail.smtp.auth", "false"); mailSender.setJavaMailProperties(props); } } if (wiser.getMessages() != null) { wiser.getMessages().clear(); } }
From source file:ejportal.webapp.action.BaseActionTestCase.java
/** * {@inheritDoc}//from w w w. ja v a 2 s.c om */ @Override protected void onSetUpBeforeTransaction() throws Exception { this.smtpPort = this.smtpPort + (int) (Math.random() * 100); LocalizedTextUtil.addDefaultResourceBundle(Constants.BUNDLE_KEY); // Initialize ActionContext final ConfigurationManager configurationManager = new ConfigurationManager(); configurationManager.addContainerProvider(new XWorkConfigurationProvider()); final Configuration config = configurationManager.getConfiguration(); final Container container = config.getContainer(); final ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack(); stack.getContext().put(ActionContext.CONTAINER, container); ActionContext.setContext(new ActionContext(stack.getContext())); ActionContext.getContext().setSession(new HashMap<String, Object>()); // change the port on the mailSender so it doesn't conflict with an // existing SMTP server on localhost final JavaMailSenderImpl mailSender = (JavaMailSenderImpl) this.applicationContext.getBean("mailSender"); mailSender.setPort(this.getSmtpPort()); mailSender.setHost("localhost"); // populate the request so getRequest().getSession() doesn't fail in // BaseAction.java ServletActionContext.setRequest(new MockHttpServletRequest()); }
From source file:alfio.manager.system.SmtpMailer.java
private JavaMailSender toMailSender(Event event) { JavaMailSenderImpl r = new CustomJavaMailSenderImpl(); r.setDefaultEncoding("UTF-8"); r.setHost(configurationManager .getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_HOST))); r.setPort(Integer.valueOf(configurationManager .getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PORT)))); r.setProtocol(configurationManager/*from ww w .j av a2 s . co m*/ .getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PROTOCOL))); r.setUsername(configurationManager.getStringConfigValue( Configuration.from(event.getOrganizationId(), event.getId(), SMTP_USERNAME), null)); r.setPassword(configurationManager.getStringConfigValue( Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PASSWORD), null)); String properties = configurationManager.getStringConfigValue( Configuration.from(event.getOrganizationId(), event.getId(), SMTP_PROPERTIES), null); if (properties != null) { try { Properties prop = PropertiesLoaderUtils.loadProperties(new EncodedResource( new ByteArrayResource(properties.getBytes(StandardCharsets.UTF_8)), "UTF-8")); r.setJavaMailProperties(prop); } catch (IOException e) { log.warn("error while setting the mail sender properties", e); } } return r; }
From source file:org.craftercms.social.services.system.EmailService.java
private JavaMailSender loadConfig(final String cacheKey, final Map<String, Object> emailPreferences) throws SocialException { if (emailPreferences != null) { JavaMailSenderImpl toReturn = new JavaMailSenderImpl(); toReturn.setDefaultEncoding(emailPreferences.get("encoding").toString()); toReturn.setHost(emailPreferences.get("host").toString()); toReturn.setPort(NumberUtils.toInt(emailPreferences.get("port").toString(), 25)); final Properties javaMailProps = new Properties(); if (Boolean.parseBoolean(emailPreferences.get("auth").toString())) { toReturn.setUsername(emailPreferences.get("username").toString()); toReturn.setPassword(emailPreferences.get("password").toString()); javaMailProps.put("mail.smtp.auth", "true"); }/*from w w w.j ava 2 s . c o m*/ if (Boolean.parseBoolean(emailPreferences.get("tls").toString())) { javaMailProps.put("mail.smtp.starttls.enable", "true"); } toReturn.setJavaMailProperties(javaMailProps); emailConfigCache.put(new Element(cacheKey, toReturn)); return toReturn; } else { throw new SocialException("Email is not configure for context " + cacheKey); } }
From source file:com.MockGatewayApplication.java
@Bean public JavaMailSender mailSender() { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); // mailSender.setHost("localhost"); // mailSender.setPort(25); mailSender.setHost(mailHost); mailSender.setPort(mailPort);/* ww w. j a v a 2 s. c o m*/ mailSender.setUsername(mailUsername); mailSender.setPassword(mailPassword); Properties properties = new Properties(); properties.setProperty("mail.smtp.auth", "true"); properties.setProperty("mail.smtp.starttls.enable", "true"); mailSender.setJavaMailProperties(properties); return mailSender; }
From source file:com.pamarin.income.component.MailSenderImpl.java
private JavaMailSender senderSetup() throws IOException { Properties config = loadMailConfig(); Properties pro = propertiesSetup(); String username = config.getProperty("email.username"); String password = config.getProperty("email.password"); if (username == null) { throw new UncheckedMailException("require property email.username on classpath:" + EMAIL_CONFIG); }/*from w w w.ja v a 2 s . c o m*/ if (password == null) { throw new UncheckedMailException("require property email.password on classpath:" + EMAIL_CONFIG); } JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setJavaMailProperties(pro); sender.setUsername(username); sender.setPassword(password); sender.setProtocol("smtps"); sender.setPort(465); sender.setHost(SMTP_HOST_NAME); sender.setDefaultEncoding("utf-8"); return sender; }
From source file:org.trustedanalytics.user.invite.config.InvitationsConfig.java
@Bean(name = "emailService") protected EmailService emailService() throws UnsupportedEncodingException { JavaMailSenderImpl sender = new JavaMailSenderImpl(); int port = smtpProperties.getPort(); if (port > 0) { sender.setPort(port);//from w ww. j a va 2 s . c o m } sender.setProtocol(smtpProperties.getProtocol()); sender.setHost(smtpProperties.getHost()); Properties mailProps = new Properties(); if (!StringUtils.isBlank(smtpProperties.getUsername()) && !StringUtils.isBlank(smtpProperties.getPassword())) { sender.setUsername(smtpProperties.getUsername()); sender.setPassword(smtpProperties.getPassword()); mailProps.setProperty(String.format("mail.%s.auth", smtpProperties.getProtocol()), "true"); } else { mailProps.setProperty(String.format("mail.%s.auth", smtpProperties.getProtocol()), "false"); } if ("smtps".equals(smtpProperties.getProtocol())) { mailProps.setProperty("mail.smtps.ssl.enable", "true"); } mailProps.setProperty("mail.smtps.connectiontimeout", Integer.toString(smtpProperties.getTimeout())); if (smtpProperties.isDebug()) { mailProps.setProperty("mail.debug", "true"); System.setProperty("mail.socket.debug", "true"); } sender.setJavaMailProperties(mailProps); return new EmailService(sender, smtpProperties.getEmail(), smtpProperties.getEmailName()); }
From source file:cn.org.once.cstack.initializer.CloudUnitApplicationContext.java
@Bean @Conditional(value = EmailActiveCondition.class) public JavaMailSender mailSender(@Value("${email.host}") String host, @Value("${email.port}") Integer port, @Value("${email.protocol}") String protocol, @Value("${email.username}") String username, @Value("${email.password}") String password) throws IOException { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(host); mailSender.setPort(port);// ww w .j a va2s .co m mailSender.setProtocol(protocol); mailSender.setUsername(username); mailSender.setPassword(password); mailSender.setJavaMailProperties(javaMailProperties()); return mailSender; }