List of usage examples for org.springframework.mail.javamail JavaMailSenderImpl setPort
public void setPort(int port)
From source file:com.gst.infrastructure.reportmailingjob.service.ReportMailingJobEmailServiceImpl.java
@Override public void sendEmailWithAttachment(ReportMailingJobEmailData reportMailingJobEmailData) { try {/*from w w w .j av a 2 s .c o m*/ // get all ReportMailingJobConfiguration objects from the database this.reportMailingJobConfigurationDataCollection = this.reportMailingJobConfigurationReadPlatformService .retrieveAllReportMailingJobConfigurations(); JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl(); javaMailSenderImpl.setHost(this.getGmailSmtpServer()); javaMailSenderImpl.setPort(this.getGmailSmtpPort()); javaMailSenderImpl.setUsername(this.getGmailSmtpUsername()); javaMailSenderImpl.setPassword(this.getGmailSmtpPassword()); javaMailSenderImpl.setJavaMailProperties(this.getJavaMailProperties()); MimeMessage mimeMessage = javaMailSenderImpl.createMimeMessage(); // use the true flag to indicate you need a multipart message MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true); mimeMessageHelper.setTo(reportMailingJobEmailData.getTo()); mimeMessageHelper.setText(reportMailingJobEmailData.getText()); mimeMessageHelper.setSubject(reportMailingJobEmailData.getSubject()); if (reportMailingJobEmailData.getAttachment() != null) { mimeMessageHelper.addAttachment(reportMailingJobEmailData.getAttachment().getName(), reportMailingJobEmailData.getAttachment()); } javaMailSenderImpl.send(mimeMessage); } catch (MessagingException e) { // handle the exception e.printStackTrace(); } }
From source file:br.com.semanticwot.cd.conf.AppWebConfiguration.java
@Bean public JavaMailSenderImpl mailSender() { // para consegui fazer a injeo automtica JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl(); javaMailSenderImpl.setHost("smtp.gmail.com"); javaMailSenderImpl.setPassword("senhadeapp"); javaMailSenderImpl.setPort(587); javaMailSenderImpl.setUsername("wiser"); Properties mailProperties = new Properties(); mailProperties.put("mail.smtp.auth", true); mailProperties.put("mail.smtp.starttls.enable", true); javaMailSenderImpl.setJavaMailProperties(mailProperties); return javaMailSenderImpl; }
From source file:com.MockGatewayApplication.java
@Bean public JavaMailSender mailSender() { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); // mailSender.setHost("localhost"); // mailSender.setPort(25); mailSender.setHost(mailHost);/*from w w w. ja v a 2 s .co m*/ mailSender.setPort(mailPort); 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: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 .ja va 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.springsource.insight.plugin.mail.MessageSendOperationCollectionAspectTest.java
private void testSendMessage(int port) { JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost(NetworkAddressUtil.LOOPBACK_ADDRESS); sender.setProtocol(JavaMailSenderImpl.DEFAULT_PROTOCOL); sender.setPort(port); SimpleMailMessage message = new SimpleMailMessage(); message.setFrom("from@com.springsource.insight.plugin.mail"); message.setTo("to@com.springsource.insight.plugin.mail"); message.setCc("cc@com.springsource.insight.plugin.mail"); message.setBcc("bcc@com.springsource.insight.plugin.mail"); Date now = new Date(System.currentTimeMillis()); message.setSentDate(now);/* w ww .j a v a 2s . co m*/ message.setSubject(now.toString()); message.setText("Test at " + now.toString()); sender.send(message); Operation op = getLastEntered(); assertNotNull("No operation extracted", op); assertEquals("Mismatched operation type", MailDefinitions.SEND_OPERATION, op.getType()); assertEquals("Mismatched protocol", sender.getProtocol(), op.get(MailDefinitions.SEND_PROTOCOL, String.class)); assertEquals("Mismatched host", sender.getHost(), op.get(MailDefinitions.SEND_HOST, String.class)); if (port == -1) { assertEquals("Mismatched default port", 25, op.getInt(MailDefinitions.SEND_PORT, (-1))); } else { assertEquals("Mismatched send port", sender.getPort(), op.getInt(MailDefinitions.SEND_PORT, (-1))); } if (getAspect().collectExtraInformation()) { assertAddresses(op, MailDefinitions.SEND_SENDERS, 1); assertAddresses(op, MailDefinitions.SEND_RECIPS, 3); OperationMap details = op.get(MailDefinitions.SEND_DETAILS, OperationMap.class); assertNotNull("No details extracted", details); assertEquals("Mismatched subject", message.getSubject(), details.get(MailDefinitions.SEND_SUBJECT, String.class)); } }
From source file:com.enonic.cms.core.mail.MailServiceBeans.java
@Bean public JavaMailSender javaMailSender() { JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl(); javaMailSender.setHost(smtpHost);//from w ww . jav a2 s .c om if (StringUtils.isNotEmpty(smtpUser)) { javaMailSender.setUsername(smtpUser); } if (StringUtils.isNotEmpty(smtpPassword)) { javaMailSender.setPassword(smtpPassword); } javaMailSender.setPort(smtpPort); return javaMailSender; }
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);/* w w w . j av a 2 s. c o m*/ mailSender.setPort(port); mailSender.setProtocol(protocol); mailSender.setUsername(username); mailSender.setPassword(password); mailSender.setJavaMailProperties(javaMailProperties()); return mailSender; }
From source file:com.github.javarch.support.config.EMailConfig.java
/** * http://support.google.com/mail/bin/answer.py?hl=en&answer=13287 * @return/* ww w . ja v a2s.co m*/ */ @Bean public MailSender mailSender() { JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setDefaultEncoding("UTF-8"); mailSender.setHost(env.getRequiredProperty("mail.host")); mailSender.setPassword(env.getRequiredProperty("mail.password")); mailSender.setUsername(env.getRequiredProperty("mail.username")); mailSender.setPort(env.getProperty("mail.port", Integer.class, 25)); mailSender.setProtocol(env.getRequiredProperty("mail.transport.protocol")); mailSender.setJavaMailProperties(mailProperties()); return mailSender; }
From source file:org.syncope.core.scheduling.NotificationJob.java
public TaskExec executeSingle(final NotificationTask task) { init();/*from w w w . j av a 2 s . co m*/ TaskExec execution = new TaskExec(); execution.setTask(task); execution.setStartDate(new Date()); if (StringUtils.isBlank(smtpHost) || StringUtils.isBlank(task.getSender()) || StringUtils.isBlank(task.getSubject()) || task.getRecipients().isEmpty() || StringUtils.isBlank(task.getHtmlBody()) || StringUtils.isBlank(task.getTextBody())) { String message = "Could not fetch all required information for " + "sending e-mails:\n" + smtpHost + ":" + smtpPort + "\n" + task.getRecipients() + "\n" + task.getSender() + "\n" + task.getSubject() + "\n" + task.getHtmlBody() + "\n" + task.getTextBody(); LOG.error(message); execution.setStatus(Status.NOT_SENT.name()); if (task.getTraceLevel().ordinal() >= TraceLevel.FAILURES.ordinal()) { execution.setMessage(message); } } else { if (LOG.isDebugEnabled()) { LOG.debug("About to send e-mails:\n" + smtpHost + ":" + smtpPort + "\n" + task.getRecipients() + "\n" + task.getSender() + "\n" + task.getSubject() + "\n" + task.getHtmlBody() + "\n" + task.getTextBody() + "\n"); } for (String to : task.getRecipients()) { try { JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost(smtpHost); sender.setPort(smtpPort); if (StringUtils.isNotBlank(smtpUsername)) { sender.setUsername(smtpUsername); } if (StringUtils.isNotBlank(smtpPassword)) { sender.setPassword(smtpPassword); } MimeMessage message = sender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setTo(to); helper.setFrom(task.getSender()); helper.setSubject(task.getSubject()); helper.setText(task.getTextBody(), task.getHtmlBody()); sender.send(message); execution.setStatus(Status.SENT.name()); StringBuilder report = new StringBuilder(); switch (task.getTraceLevel()) { case ALL: report.append("FROM: ").append(task.getSender()).append('\n').append("TO: ").append(to) .append('\n').append("SUBJECT: ").append(task.getSubject()).append('\n') .append('\n').append(task.getTextBody()).append('\n').append('\n') .append(task.getHtmlBody()).append('\n'); break; case SUMMARY: report.append("E-mail sent to ").append(to).append('\n'); break; case FAILURES: case NONE: default: } if (report.length() > 0) { execution.setMessage(report.toString()); } } catch (Throwable t) { LOG.error("Could not send e-mail", t); execution.setStatus(Status.NOT_SENT.name()); StringWriter exceptionWriter = new StringWriter(); exceptionWriter.write(t.getMessage() + "\n\n"); t.printStackTrace(new PrintWriter(exceptionWriter)); if (task.getTraceLevel().ordinal() >= TraceLevel.FAILURES.ordinal()) { execution.setMessage(exceptionWriter.toString()); } } execution.setEndDate(new Date()); } } if (hasToBeRegistered(execution)) { execution = taskExecDAO.save(execution); } return execution; }
From source file:com.miserablemind.butter.bootstrap.RootContext.java
/** * E-mail Sender configured using {@link ConfigMail}. * * @return {@link JavaMailSender} bean./* w w w .ja v a 2 s .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; }