List of usage examples for org.springframework.mail.javamail JavaMailSenderImpl setPort
public void setPort(int port)
From source file:io.lavagna.model.MailConfig.java
private JavaMailSender toMailSender() { JavaMailSenderImpl r = new JavaMailSenderImpl(); r.setDefaultEncoding("UTF-8"); r.setHost(host);/*from ww w . j a v a 2 s . com*/ r.setPort(port); r.setProtocol(protocol); r.setUsername(username); r.setPassword(password); if (properties != null) { try { Properties prop = PropertiesLoaderUtils.loadProperties( new EncodedResource(new ByteArrayResource(properties.getBytes("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:ca.airspeed.demo.testingemail.EmailServiceTest.java
private EmailService makeALocalMailer() throws Exception { EmailService service = new EmailService(); JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost("localhost"); sender.setPort(2525); ReflectionTestUtils.setField(service, "mailSender", sender); ReflectionTestUtils.setField(service, "senderAddress", new InternetAddress("admin@domain.com", "Domain Admin")); return service; }
From source file:com.springsource.greenhouse.config.MailConfig.java
/** * The Java Mail sender.//from w w w . ja v a 2s .co m * It's not generally expected for mail sending to work in embedded mode. * Since this mail sender is always invoked asynchronously, this won't cause problems for the developer. */ @Bean public JavaMailSender mailSender() { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setDefaultEncoding("UTF-8"); mailSender.setHost(environment.getProperty("mail.host")); mailSender.setPort(environment.getProperty("mail.port", Integer.class, 25)); mailSender.setUsername(environment.getProperty("mail.username")); mailSender.setPassword(environment.getProperty("mail.password")); Properties properties = new Properties(); properties.put("mail.smtp.auth", environment.getProperty("mail.smtp.auth", Boolean.class, false)); properties.put("mail.smtp.starttls.enable", environment.getProperty("mail.smtp.starttls.enable", Boolean.class, false)); mailSender.setJavaMailProperties(properties); return mailSender; }
From source file:nz.net.orcon.kanban.automation.actions.EmailSenderAction.java
public void sendSecureEmail(String subject, String emailBody, String to, String bcc, String from, String replyTo, String host, String password) { SimpleMailMessage mailMessage = new SimpleMailMessage(); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(host);//from ww w . j a v a2 s . c o m mailSender.setPort(587); mailSender.setProtocol("smtp"); Properties props = new Properties(); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); mailSender.setJavaMailProperties(props); if (StringUtils.isNotBlank(to)) { mailMessage.setTo(to); } if (StringUtils.isNotBlank(bcc)) { mailMessage.setBcc(bcc); } if (StringUtils.isNotBlank(from)) { mailMessage.setFrom(from); mailSender.setUsername(from); } if (StringUtils.isNotBlank(password)) { mailSender.setPassword(password); } if (StringUtils.isNotBlank(replyTo)) { mailMessage.setReplyTo(replyTo); } if (StringUtils.isNotBlank(subject)) { mailMessage.setSubject(subject); } mailMessage.setText(emailBody); mailSender.send(mailMessage); logger.info("Secure Email Message has been sent.."); }
From source file:ejportal.webapp.action.BaseActionTestCase.java
/** * {@inheritDoc}/*from w ww . jav a 2s .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:org.homiefund.config.ApplicationConfiguration.java
@Bean @Description("Service responsible for sending emails.") public MailSender mailSender() { // todo move to application config JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost("localhost"); mailSender.setPort(20025); return mailSender; }
From source file:io.gravitee.management.rest.spring.EmailConfiguration.java
@Bean public JavaMailSenderImpl mailSender() { final JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(host);//from w ww .jav a2s . co m if (StringUtils.isNumeric(port)) { javaMailSender.setPort(Integer.valueOf(this.port)); } javaMailSender.setUsername(username); javaMailSender.setPassword(password); return javaMailSender; }
From source file:com.glaf.mail.config.JavaMailSenderConfiguration.java
@Bean(name = "javaMailSender") public JavaMailSenderImpl buildJavaMailSender() { MailConfig cfg = new MailConfig(); String filename = SystemProperties.getConfigRootPath() + Constants.MAIL_CONFIG; Properties properties = PropertiesUtils.loadFilePathResource(filename); cfg.setEncoding(properties.getProperty("mail.defaultEncoding", "GBK")); cfg.setHost(properties.getProperty("mail.host", "127.0.0.1")); cfg.setUsername(properties.getProperty("mail.username")); cfg.setPassword(properties.getProperty("mail.password")); if (StringUtils.equals(properties.getProperty("mail.auth"), "true")) { cfg.setAuth(true);//from www .ja v a 2s . co m } int port = JavaMailSenderImpl.DEFAULT_PORT; if (properties.getProperty("mail.port") != null) { port = Integer.parseInt(properties.getProperty("mail.port")); } JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setJavaMailProperties(properties); sender.setHost(properties.getProperty("mail.host")); sender.setPort(port); sender.setProtocol(JavaMailSenderImpl.DEFAULT_PROTOCOL); sender.setUsername(properties.getProperty("mail.username")); sender.setPassword(properties.getProperty("mail.password")); sender.setDefaultEncoding(properties.getProperty("mail.defaultEncoding", "GBK")); return sender; }
From source file:com.github.dbourdette.otto.service.mail.Mailer.java
private JavaMailSender mailSender(MailConfiguration configuration) { JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost(configuration.getSmtp()); if (configuration.getPort() != 0) { sender.setPort(configuration.getPort()); }/*from w w w. j a v a2 s . c om*/ if (StringUtils.isNotEmpty(configuration.getUser())) { sender.setUsername(configuration.getUser()); sender.setPassword(configuration.getPassword()); Properties javaMailProperties = new Properties(); javaMailProperties.put("mail.smtp.auth", "true"); sender.setJavaMailProperties(javaMailProperties); } 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 ww w .j ava 2 s. c om*/ 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()); }