/** * Send. * * @param mailMessage the mail message * @throws MessagingException the messaging exception */ public void send(MailMessage mailMessage) throws MessagingException { Properties props = (Properties) System.getProperties().clone(); if (smtp != null) { props.put(PROPERTY_KEY_SMTP, smtp); } try (PrintStream debugOut = LogOutputStream.createPrintStream(logger, LogOutputStream.LEVEL_DEBUG)) { Session session = Session.getDefaultInstance(props); session.setDebug(true); session.setDebugOut(debugOut); MimeMessage message = createMimeMessage(session, mailMessage); logger.debug("Sending message"); Transport.send(message); } }
/** * Enable or disable the underlying implementation's debug flag, if * there is one. Debug messages are to be written to the supplied * <tt>PrintStream</tt>. * * @param debug <tt>true</tt> to enable debug, <tt>false</tt> to * disable it * @param out where to dump debug messages, or null for standard * output. Ignored unless <tt>debug</tt> is <tt>true</tt>. */ public void setDebug(boolean debug, PrintStream out) { session.setDebug(debug); if (debug) session.setDebugOut(out); }
ByteArrayOutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); Session mailSession = Session.getDefaultInstance(props, null); try { if (MAIL_DEBUG) { logger.info("JAVAMAIL debug mode is ON"); mailSession.setDebugOut(ps); mailSession.setDebug(true); } ... transport.close(); if (MAIL_DEBUG) { logger.info(os); } } finally { ps.close(); os.close(); }
/** * <p>setDebug</p> * * @param debug a boolean. */ public void setDebug(boolean debug) { if (debug) { m_session.setDebugOut(new PrintStream(new LoggingByteArrayOutputStream())); } m_session.setDebug(debug); }
/** * <p>setDebug</p> * * @param debug a boolean. */ public void setDebug(boolean debug) { if (debug) { m_session.setDebugOut(new PrintStream(new LoggingByteArrayOutputStream())); } m_session.setDebug(debug); }
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Reference ref = (Reference) obj; if(_logger.isLoggable(Level.FINE)) { _logger.log(Level.FINE,"MailNamingObjectFactory: " + ref + " Name:" + name); } MailConfiguration config = (MailConfiguration) ref.get(0).getContent(); // Note: javax.mail.Session is not serializable, // but we need to get a new instance on every lookup. Properties props = config.getMailProperties(); javax.mail.Session s = javax.mail.Session.getInstance(props, new MailSessionAuthenticator(props)); if("smtps".equals(props.getProperty("mail.transport.protocol"))) { s.setProtocolForAddress("rfc822", "smtps"); } s.setDebugOut(new PrintStream(new MailLogOutputStream())); s.setDebug(true); return s; } }
/** * Enable debugging and return the stream * @return */ public void setDebug(PrintStream stream) { senderImpl.getSession().setDebug(true); senderImpl.getSession().setDebugOut(stream); }
session.setDebugOut(f);
@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)); } } 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))); } } }
/** * <p>setDebug</p> * * @param debug a boolean. */ public void setDebug(boolean debug) { m_debug = debug; if (isDebug()) { m_session.setDebugOut(new PrintStream(new LoggingByteArrayOutputStream())); } m_session.setDebug(isDebug()); }
/** * <p>setDebug</p> * * @param debug a boolean. */ public void setDebug(boolean debug) { m_debug = debug; if (isDebug()) { m_session.setDebugOut(new PrintStream(new LoggingByteArrayOutputStream())); } m_session.setDebug(isDebug()); }
protected Session getSessionFromServerManager(Properties props, final Authenticator authenticator) throws MailException { log.debug("Getting session"); if (getDebug()) { log.debug("Debug messages from JavaMail session initialization will not appear in this log." + " These messages are sent to standard out."); } final Session session = MailFactory.getServerManager().getSession(props, authenticator); if (log.isDebugEnabled()) { getMoreDebugInfoAboutCreatedSession(session); } if (getDebugStream() != null) { try { session.setDebugOut(getDebugStream()); } catch (NoSuchMethodError nsme) { // JRA-8543 log.error("Warning: An old (pre-1.3.2) version of the JavaMail library (javamail.jar or mail.jar) bundled with your app server, is in use. Some functions such as IMAPS/POPS/SMTPS will not work. Consider upgrading the app server's javamail jar to the version JIRA provides."); } } return session; }
mailSession.setDebugOut(ps);
JTextArea area = new JTextArea(); Adaptor out = new Adaptor(area.getDocument()); s.setDebugOut(new PrintStream(out, true)); //Default encoding? s.setDebug(true); System.out.println(area.getText());
private Session getSession() { Properties properties = new Properties(); properties.put("mail.smtp.host", smtpEmailConfiguration.getServerHostname()); properties.put("mail.smtp.port", smtpEmailConfiguration.getServerPort()); Authenticator authenticator = null; switch (smtpEmailConfiguration.getServerAuthentication()) { case NONE: // no additional properties required break; case TLS: properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.starttls.enable", "true"); authenticator = getAuthenticator(); break; case SSL: properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.socketFactory.port", smtpEmailConfiguration.getServerPort()); properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); authenticator = getAuthenticator(); break; default: throw new VisalloException("unexpected MailServerAuthentication: " + smtpEmailConfiguration.getServerAuthentication().toString()); } Session session = Session.getDefaultInstance(properties, authenticator); if (LOGGER.isTraceEnabled()) { session.setDebugOut(new LoggerPrintStream(LOGGER)); session.setDebug(true); } return session; }
public static void setupLogging(Session session, Log log, ParameterInclude params) throws AxisFault { // Note that debugging might already be enabled by the mail.debug property and we should // take care to override it. if (log.isTraceEnabled()) { // This is the old behavior: just set debug to true session.setDebug(true); } if (ParamUtils.getOptionalParamBoolean(params, MailConstants.TRANSPORT_MAIL_DEBUG, false)) { // Redirect debug output to where it belongs, namely to the logs! session.setDebugOut(new PrintStream(new WriterOutputStream(new LogWriter(log)), true)); // Only enable debug afterwards since the call to setDebug might already cause debug output session.setDebug(true); } } }
public static void setupLogging(Session session, Log log, ParameterInclude params) throws AxisFault { // Note that debugging might already be enabled by the mail.debug property and we should // take care to override it. if (log.isTraceEnabled()) { // This is the old behavior: just set debug to true session.setDebug(true); } if (ParamUtils.getOptionalParamBoolean(params, MailConstants.TRANSPORT_MAIL_DEBUG, false)) { // Redirect debug output to where it belongs, namely to the logs! session.setDebugOut(new PrintStream(new WriterOutputStream(new LogWriter(log)), true)); // Only enable debug afterwards since the call to setDebug might already cause debug output session.setDebug(true); } } }
public static void setupLogging(Session session, Log log, ParameterInclude params) throws AxisFault { // Note that debugging might already be enabled by the mail.debug property and we should // take care to override it. if (log.isTraceEnabled()) { // This is the old behavior: just set debug to true session.setDebug(true); } if (ParamUtils.getOptionalParamBoolean(params, MailConstants.TRANSPORT_MAIL_DEBUG, false)) { // Redirect debug output to where it belongs, namely to the logs! session.setDebugOut(new PrintStream(new WriterOutputStream(new LogWriter(log)), true)); // Only enable debug afterwards since the call to setDebug might already cause debug output session.setDebug(true); } } }
/** * Instantiates a new java send mailer. * <p>Constructs everything required to call send().</p> * * @param config the sendmail configuration * @param useJmProps a boolean representing the handling of the deprecated javamail-configuration.properties file. * @throws JavaMailerException the java mailer exception */ public JavaSendMailer(SendmailConfig config, boolean useJmProps) throws JavaMailerException { m_config = config; try { m_session = Session.getInstance(createProps(useJmProps), createAuthenticator()); if (config.getSendmailMessage() != null) { m_message = buildMimeMessage(config.getSendmailMessage()); } else { throw new JavaMailerException("Unable to build mime message: sendmail-message missing from config!"); } if (m_config.isDebug()) { m_session.setDebugOut(new PrintStream(new LoggingByteArrayOutputStream())); } m_session.setDebug(m_config.isDebug()); } catch (IOException e) { throw new JavaMailerException("IO problem creating session", e); } }
/** * Instantiates a new java send mailer. * <p>Constructs everything required to call send().</p> * * @param config the sendmail configuration * @param useJmProps a boolean representing the handling of the deprecated javamail-configuration.properties file. * @throws JavaMailerException the java mailer exception */ public JavaSendMailer(SendmailConfig config, boolean useJmProps) throws JavaMailerException { m_config = config; try { m_session = Session.getInstance(createProps(useJmProps), createAuthenticator()); if (config.getSendmailMessage() != null) { m_message = buildMimeMessage(config.getSendmailMessage()); } else { throw new JavaMailerException("Unable to build mime message: sendmail-message missing from config!"); } if (m_config.isDebug()) { m_session.setDebugOut(new PrintStream(new LoggingByteArrayOutputStream())); } m_session.setDebug(m_config.isDebug()); } catch (IOException e) { throw new JavaMailerException("IO problem creating session", e); } }