List of usage examples for javax.mail Session getProperty
public String getProperty(String name)
From source file:org.seedstack.javamail.internal.PropertyFileSessionConfigurerTest.java
@Test public void test_imap_session_configuration_is_present() { assertThat(sessionsConfig).containsKey("imap"); final Session imap = sessionsConfig.get("imap"); assertThat(imap).isNotNull();//from w w w. jav a 2 s . c om assertThat(imap.getProperty("mail.imap.user")).isEqualTo("toto_user@ext.mpsa.com"); assertThat(imap.getProperty("mail.imap.host")).isEqualTo("testserver3"); assertThat(imap.getProperty("mail.imap.auth.login.disable")).isEqualTo(Boolean.FALSE.toString()); assertThat(imap.getProperty("mail.imap.auth.plain.disable")).isEqualTo(Boolean.TRUE.toString()); }
From source file:org.seedstack.javamail.internal.PropertyFileSessionConfigurerTest.java
@Test public void test_pop3_session_configuration_is_present() { assertThat(sessionsConfig).containsKey("pop3"); final Session pop3 = sessionsConfig.get("pop3"); assertThat(pop3.getProperty("mail.pop3.host")).isEqualTo("testserver4"); assertThat(pop3).isNotNull();/* www .jav a2 s .c om*/ }
From source file:org.sourceforge.net.javamail4ews.util.Util.java
private static Integer getConnectionTimeout(Session pSession) { Integer connectionTimeout = null; String cnxTimeoutStr = pSession.getProperty("mail.pop3.connectiontimeout"); if (cnxTimeoutStr != null) { connectionTimeout = Integer.valueOf(cnxTimeoutStr); }/*from w ww .j ava 2s . c om*/ return connectionTimeout; }
From source file:org.sourceforge.net.javamail4ews.util.Util.java
private static Integer getProtocolTimeout(Session pSession) { Integer protocolTimeout = null; String protTimeoutStr = pSession.getProperty("mail.pop3.timeout"); if (protTimeoutStr != null) { protocolTimeout = Integer.valueOf(protTimeoutStr); }/*from www. jav a 2s . c om*/ return protocolTimeout; }
From source file:org.xwiki.commons.internal.DefaultMailSender.java
@Override public int send(Mail mail) { Session session = null; Transport transport = null;/*from w w w . ja v a2 s . c o m*/ if ((mail.getTo() == null || StringUtils.isEmpty(mail.getTo())) && (mail.getCc() == null || StringUtils.isEmpty(mail.getCc())) && (mail.getBcc() == null || StringUtils.isEmpty(mail.getBcc()))) { logger.error("This mail has no recipient"); return 0; } if (mail.getContents().size() == 0) { logger.error("This mail is empty. You should add a content"); return 0; } try { if ((transport == null) || (session == null)) { logger.info("Sending mail : Initializing properties"); Properties props = initProperties(); session = Session.getInstance(props, null); transport = session.getTransport("smtp"); if (session.getProperty("mail.smtp.auth") == "true") transport.connect(session.getProperty("mail.smtp.server.username"), session.getProperty("mail.smtp.server.password")); else transport.connect(); try { Multipart wrapper = generateMimeMultipart(mail); InternetAddress[] adressesTo = this.toInternetAddresses(mail.getTo()); MimeMessage message = new MimeMessage(session); message.setSentDate(new Date()); message.setSubject(mail.getSubject()); message.setFrom(new InternetAddress(mail.getFrom())); message.setRecipients(javax.mail.Message.RecipientType.TO, adressesTo); if (mail.getReplyTo() != null && !StringUtils.isEmpty(mail.getReplyTo())) { logger.info("Adding ReplyTo field"); InternetAddress[] adressesReplyTo = this.toInternetAddresses(mail.getReplyTo()); if (adressesReplyTo.length != 0) message.setReplyTo(adressesReplyTo); } if (mail.getCc() != null && !StringUtils.isEmpty(mail.getCc())) { logger.info("Adding Cc recipients"); InternetAddress[] adressesCc = this.toInternetAddresses(mail.getCc()); if (adressesCc.length != 0) message.setRecipients(javax.mail.Message.RecipientType.CC, adressesCc); } if (mail.getBcc() != null && !StringUtils.isEmpty(mail.getBcc())) { InternetAddress[] adressesBcc = this.toInternetAddresses(mail.getBcc()); if (adressesBcc.length != 0) message.setRecipients(javax.mail.Message.RecipientType.BCC, adressesBcc); } message.setContent(wrapper); message.setSentDate(new Date()); transport.sendMessage(message, message.getAllRecipients()); transport.close(); } catch (SendFailedException sfex) { logger.error("Error encountered while trying to send the mail"); logger.error("SendFailedException has occured.", sfex); try { transport.close(); } catch (MessagingException Mex) { logger.error("MessagingException has occured.", Mex); } return 0; } catch (MessagingException mex) { logger.error("Error encountered while trying to send the mail"); logger.error("MessagingException has occured.", mex); try { transport.close(); } catch (MessagingException ex) { logger.error("MessagingException has occured.", ex); } return 0; } } } catch (Exception e) { System.out.println(e.toString()); logger.error("Error encountered while trying to setup mail properties"); try { if (transport != null) { transport.close(); } } catch (MessagingException ex) { logger.error("MessagingException has occured.", ex); } return 0; } return 1; }