Java 类javax.mail.event.TransportEvent 实例源码

项目:javamail-mock2    文件:MockTransport.java   
@Override
public void sendMessage(final Message msg, final Address[] addresses) throws MessagingException {
    for (final Address a : addresses) {
        final MockMailbox mailbox = MockMailbox.get(a);
        if (mailbox.getInbox().isSimulateError()) {

            notifyTransportListeners(TransportEvent.MESSAGE_NOT_DELIVERED, new Address[0], addresses, new Address[0], msg);

            throw new MessagingException("Simulated error sending message to " + a);

        }

        mailbox.getInbox().add(new MimeMessage((MimeMessage) msg));
        notifyTransportListeners(TransportEvent.MESSAGE_DELIVERED, addresses, new Address[0], new Address[0], msg);
    }
}
项目:opennmszh    文件:JavaMailer2.java   
private void logEvent(String message, TransportEvent event) {
    if (event.getInvalidAddresses() != null && event.getInvalidAddresses().length > 0) {
        m_invalidAddresses.addAll(Arrays.asList(event.getInvalidAddresses()));
        m_category.error(message + ": invalid addresses: " + StringUtils.arrayToDelimitedString(event.getInvalidAddresses(), ", "));
    }
    if (event.getValidSentAddresses() != null && event.getValidSentAddresses().length > 0) {
        m_validSentAddresses.addAll(Arrays.asList(event.getValidSentAddresses()));
        m_category.debug(message + ": valid sent addresses: " + StringUtils.arrayToDelimitedString(event.getValidSentAddresses(), ", "));
    }
    if (event.getValidUnsentAddresses() != null && event.getValidUnsentAddresses().length > 0) {
        m_validUnsentAddresses.addAll(Arrays.asList(event.getValidUnsentAddresses()));
        m_category.error(message + ": valid unsent addresses: " + StringUtils.arrayToDelimitedString(event.getValidUnsentAddresses(), ", "));
    }
}
项目:OpenNMS    文件:JavaMailer2.java   
private void logEvent(String message, TransportEvent event) {
    if (event.getInvalidAddresses() != null && event.getInvalidAddresses().length > 0) {
        m_invalidAddresses.addAll(Arrays.asList(event.getInvalidAddresses()));
        m_category.error(message + ": invalid addresses: " + StringUtils.arrayToDelimitedString(event.getInvalidAddresses(), ", "));
    }
    if (event.getValidSentAddresses() != null && event.getValidSentAddresses().length > 0) {
        m_validSentAddresses.addAll(Arrays.asList(event.getValidSentAddresses()));
        m_category.debug(message + ": valid sent addresses: " + StringUtils.arrayToDelimitedString(event.getValidSentAddresses(), ", "));
    }
    if (event.getValidUnsentAddresses() != null && event.getValidUnsentAddresses().length > 0) {
        m_validUnsentAddresses.addAll(Arrays.asList(event.getValidUnsentAddresses()));
        m_category.error(message + ": valid unsent addresses: " + StringUtils.arrayToDelimitedString(event.getValidUnsentAddresses(), ", "));
    }
}
项目:ats-framework    文件:Test_SmtpSender.java   
@Override
public void sendMessage(
                         Message arg0,
                         Address[] arg1 ) throws MessagingException {

    log.info("Fake message sending");

    if (deliveryState == DELIVERY_STATE.DELIVERED) {
        notifyTransportListeners(TransportEvent.MESSAGE_DELIVERED, null, null, null, null);
    } else if (deliveryState == DELIVERY_STATE.PARTIALLY_DELIVERED) {
        notifyTransportListeners(TransportEvent.MESSAGE_PARTIALLY_DELIVERED, null, null, null, null);
    } else if (deliveryState == DELIVERY_STATE.ERROR_DELIVERING) {
        notifyTransportListeners(TransportEvent.MESSAGE_NOT_DELIVERED, null, null, null, null);
    }
}
项目:streamline    文件:EmailNotifier.java   
/**
 * {@inheritDoc} This acks the notification by invoking {@link NotificationContext#ack(String)}
 */
public void messageDelivered(TransportEvent event) {
    LOG.debug("Got messageDelivered event {}", event);
    String notificationId = msgNotificationMap.remove(event.getMessage());
    if (notificationId != null) {
        ctx.ack(notificationId);
    }
}
项目:javamail    文件:AbstractFileTransport.java   
@Override
public void sendMessage(Message message, Address[] addresses) throws MessagingException {
    validateAndPrepare(message, addresses);
       FileOutputStream fw = null;
       File file = null;
       try {
           String baseName = Long.toString(System.currentTimeMillis(), 32);
           file = createMessageFile(baseName);
           fw = new FileOutputStream(file);
           writeMessage(message, fw);
           notifyTransportListeners(TransportEvent.MESSAGE_DELIVERED, message.getAllRecipients(), ADDRESSES_EMPTY, ADDRESSES_EMPTY, message);
    } catch (IOException e) {
           notifyTransportListeners(TransportEvent.MESSAGE_NOT_DELIVERED, ADDRESSES_EMPTY, message.getAllRecipients(), ADDRESSES_EMPTY, message);
           if (file == null) {
               throw new MessagingException("Cennot create message file", e);
           } else {
               throw new MessagingException("Failed to write file " + file.getAbsolutePath(), e);
           }
    } finally {
           if (fw != null) {
               try {
                   fw.close();
               } catch (IOException ex)  {
                   Logger.getLogger(getClass().getName()).log(Level.WARNING, "Cannot close " + fw, ex);
               }
           }
       }
}
项目:javamail    文件:TransportTest.java   
@Test
public void transportNOPTest() throws Exception {
    TransportListener transportListener = Mockito.mock(TransportListener.class);
    Message message = generateMessage();
    Transport transport = session.getTransport("nop");
    transport.addTransportListener(transportListener);
    transport.sendMessage(message, toAddress);
    waitForListeners();
    ArgumentCaptor<TransportEvent> transportEventArgumentCaptor = ArgumentCaptor.forClass(TransportEvent.class);
    verify(transportListener).messageDelivered(transportEventArgumentCaptor.capture());
    TransportEvent event = transportEventArgumentCaptor.getValue();
    assertEquals(message, event.getMessage());
    assertEquals(TransportEvent.MESSAGE_DELIVERED, event.getType());
    assertArrayEquals(toAddress, event.getValidSentAddresses());
}
项目:javamail    文件:AbstractTransportTest.java   
@Test(expected = MessagingException.class)
public void testNoFromNull() throws Exception {
    try {
        message.setFrom((String) null);
        transport.validateAndPrepare(message, new Address[]{});
    } finally {
        waitForListeners();
        verify(transportListener).messageNotDelivered(any(TransportEvent.class));
    }
}
项目:opennmszh    文件:JavaMailer.java   
private void logEvent(String message, TransportEvent event) {
    if (event.getInvalidAddresses() != null && event.getInvalidAddresses().length > 0) {
        m_invalidAddresses.addAll(Arrays.asList(event.getInvalidAddresses()));
        m_category.error(message + ": invalid addresses: " + StringUtils.arrayToDelimitedString(event.getInvalidAddresses(), ", "));
    }
    if (event.getValidSentAddresses() != null && event.getValidSentAddresses().length > 0) {
        m_validSentAddresses.addAll(Arrays.asList(event.getValidSentAddresses()));
        m_category.debug(message + ": valid sent addresses: " + StringUtils.arrayToDelimitedString(event.getValidSentAddresses(), ", "));
    }
    if (event.getValidUnsentAddresses() != null && event.getValidUnsentAddresses().length > 0) {
        m_validUnsentAddresses.addAll(Arrays.asList(event.getValidUnsentAddresses()));
        m_category.error(message + ": valid unsent addresses: " + StringUtils.arrayToDelimitedString(event.getValidUnsentAddresses(), ", "));
    }
}
项目:OpenNMS    文件:JavaMailer.java   
private void logEvent(String message, TransportEvent event) {
    if (event.getInvalidAddresses() != null && event.getInvalidAddresses().length > 0) {
        m_invalidAddresses.addAll(Arrays.asList(event.getInvalidAddresses()));
        m_category.error(message + ": invalid addresses: " + StringUtils.arrayToDelimitedString(event.getInvalidAddresses(), ", "));
    }
    if (event.getValidSentAddresses() != null && event.getValidSentAddresses().length > 0) {
        m_validSentAddresses.addAll(Arrays.asList(event.getValidSentAddresses()));
        m_category.debug(message + ": valid sent addresses: " + StringUtils.arrayToDelimitedString(event.getValidSentAddresses(), ", "));
    }
    if (event.getValidUnsentAddresses() != null && event.getValidUnsentAddresses().length > 0) {
        m_validUnsentAddresses.addAll(Arrays.asList(event.getValidUnsentAddresses()));
        m_category.error(message + ": valid unsent addresses: " + StringUtils.arrayToDelimitedString(event.getValidUnsentAddresses(), ", "));
    }
}
项目:ats-framework    文件:MailTransportListener.java   
public void messageDelivered(
                              TransportEvent e ) {

    processResult(DELIVERY_STATE.DELIVERED);
}
项目:ats-framework    文件:MailTransportListener.java   
public void messageNotDelivered(
                                 TransportEvent e ) {

    processResult(DELIVERY_STATE.ERROR_DELIVERING);
}
项目:ats-framework    文件:MailTransportListener.java   
public void messagePartiallyDelivered(
                                       TransportEvent e ) {

    processResult(DELIVERY_STATE.ERROR_DELIVERING);
}
项目:cloud-meter    文件:SynchronousTransportListener.java   
/**
 * {@inheritDoc}
 */
@Override
public void messageDelivered(TransportEvent e) {
    log.debug("Message delivered");
    finish();
}
项目:cloud-meter    文件:SynchronousTransportListener.java   
/**
 * {@inheritDoc}
 */
@Override
public void messageNotDelivered(TransportEvent e) {
    log.debug("Message not delivered");
    finish();
}
项目:cloud-meter    文件:SynchronousTransportListener.java   
/**
 * {@inheritDoc}
 */
@Override
public void messagePartiallyDelivered(TransportEvent e) {
    log.debug("Message partially delivered");
    finish();
}
项目:streamline    文件:EmailNotifier.java   
/**
 * {@inheritDoc} This fails the notification by invoking {@link NotificationContext#fail(String)}
 */
public void messageNotDelivered(TransportEvent event) {
    LOG.debug("Got messageNotDelivered event {}", event);
    handleFail(event);
}
项目:streamline    文件:EmailNotifier.java   
private void handleFail(TransportEvent event) {
    String notificationId = msgNotificationMap.remove(event.getMessage());
    if (notificationId != null) {
        ctx.fail(notificationId);
    }
}
项目:javamail    文件:NopTransport.java   
@Override
public void sendMessage(Message msg, Address[] addresses) throws MessagingException {
    validateAndPrepare(msg, addresses);
    logger.info("Message {subject=" + msg.getSubject() + ", to=" + Arrays.asList(addresses) + "}");
    notifyTransportListeners(TransportEvent.MESSAGE_DELIVERED, msg.getAllRecipients(), ADDRESSES_EMPTY, ADDRESSES_EMPTY, msg);
}
项目:javamail    文件:AbstractTransport.java   
private void fail(Message message, Address[] addresses, String msg) throws MessagingException {
    Address[] empty = new Address[0];
    notifyTransportListeners(TransportEvent.MESSAGE_NOT_DELIVERED, empty, addresses, empty, message);
    throw new MessagingException(msg);
}
项目:javamail    文件:SmtpJmsTransport.java   
private void fail(Message message, Address[] addresses, String msg) throws MessagingException {
    notifyTransportListeners(TransportEvent.MESSAGE_NOT_DELIVERED, ADDRESSES_EMPTY, addresses, ADDRESSES_EMPTY, message);
    throw new MessagingException(msg);
}
项目:opennmszh    文件:JavaMailer2.java   
public void messageDelivered(TransportEvent event) {
    logEvent("message delivered", event);
}
项目:opennmszh    文件:JavaMailer2.java   
public void messageNotDelivered(TransportEvent event) {
    logEvent("message not delivered", event);
}
项目:opennmszh    文件:JavaMailer2.java   
public void messagePartiallyDelivered(TransportEvent event) {
    logEvent("message partially delivered", event);
}
项目:opennmszh    文件:JavaMailer.java   
public void messageDelivered(TransportEvent event) {
    logEvent("message delivered", event);
}
项目:opennmszh    文件:JavaMailer.java   
public void messageNotDelivered(TransportEvent event) {
    logEvent("message not delivered", event);
}
项目:opennmszh    文件:JavaMailer.java   
public void messagePartiallyDelivered(TransportEvent event) {
    logEvent("message partially delivered", event);
}
项目:apache-jmeter-2.10    文件:SynchronousTransportListener.java   
/**
 * {@inheritDoc}
 */
@Override
public void messageDelivered(TransportEvent e) {
    logger.debug("Message delivered");
    finish();
}
项目:apache-jmeter-2.10    文件:SynchronousTransportListener.java   
/**
 * {@inheritDoc}
 */
@Override
public void messageNotDelivered(TransportEvent e) {
    logger.debug("Message not delivered");
    finish();
}
项目:apache-jmeter-2.10    文件:SynchronousTransportListener.java   
/**
 * {@inheritDoc}
 */
@Override
public void messagePartiallyDelivered(TransportEvent e) {
    logger.debug("Message partially delivered");
    finish();
}
项目:OpenNMS    文件:JavaMailer2.java   
public void messageDelivered(TransportEvent event) {
    logEvent("message delivered", event);
}