Package org.springframework.mail

Examples of org.springframework.mail.MailSendException


    }

    @Test
    public void testSendActivationMailFail() {
        enableEmailNotifications();
        Exception fail = new MailSendException("");
        doThrow(fail).when(sender).send(Matchers.<SimpleMailMessage>any());

        service.sendAccountActivationMail(new JCUser(USERNAME, TO, PASSWORD));
    }
View Full Code Here


    }

    @Test(expectedExceptions = MailingFailedException.class)
    public void testRestorePasswordFail() throws NotFoundException, MailingFailedException {
        enableEmailNotifications();
        Exception fail = new MailSendException("");
        doThrow(fail).when(sender).send(Matchers.<MimeMessage>any());

        service.sendPasswordRecoveryMail(user, PASSWORD);
    }
View Full Code Here

    }

    @Test
    public void testTopicUpdateNotificationFail() throws NotFoundException {
        enableEmailNotifications();
        Exception fail = new MailSendException("");
        doThrow(fail).when(sender).send(Matchers.<SimpleMailMessage>any());

        service.sendUpdatesOnSubscription(user, topic);
    }
View Full Code Here

    }

    @Test
    public void testBranchUpdateNotificationFail() throws NotFoundException {
        enableEmailNotifications();
        Exception fail = new MailSendException("");
        doThrow(fail).when(sender).send(Matchers.<SimpleMailMessage>any());

        service.sendUpdatesOnSubscription(user, branch);
    }
View Full Code Here

    }

    @Test
    public void testSendReceivedPrivateMessageNotificationFail() {
        enableEmailNotifications();
        Exception fail = new MailSendException("");
        doThrow(fail).when(sender).send(Matchers.<SimpleMailMessage>any());

        service.sendReceivedPrivateMessageNotification(user, new PrivateMessage(null, null, null, null));
    }
View Full Code Here

    }

    @Test
    public void testSendTopicMovedMailFailed() throws Exception {
        enableEmailNotifications();
        Exception fail = new MailSendException("");
        doThrow(fail).when(sender).send(Matchers.<SimpleMailMessage>any());

        service.sendTopicMovedMail(user, topic);
       
        this.checkMailCredentials();
View Full Code Here

      else {
        received.add(simpleMessage);
      }
    }
    if (!failedMessages.isEmpty()) {
      throw new MailSendException(failedMessages);
    }
  }
View Full Code Here

    }
    catch (AuthenticationFailedException ex) {
      throw new MailAuthenticationException(ex);
    }
    catch (MessagingException ex) {
      throw new MailSendException("Mail server connection failed", ex);
    }
    if (!failedMessages.isEmpty()) {
      throw new MailSendException(failedMessages);
    }
  }
View Full Code Here

      // Effectively, all messages failed...
      for (int i = 0; i < mimeMessages.length; i++) {
        Object original = (originalMessages != null ? originalMessages[i] : mimeMessages[i]);
        failedMessages.put(original, ex);
      }
      throw new MailSendException("Mail server connection failed", ex, failedMessages);
    }

    try {
      for (int i = 0; i < mimeMessages.length; i++) {
        MimeMessage mimeMessage = mimeMessages[i];
        try {
          if (mimeMessage.getSentDate() == null) {
            mimeMessage.setSentDate(new Date());
          }
          String messageId = mimeMessage.getMessageID();
          mimeMessage.saveChanges();
          if (messageId != null) {
            // Preserve explicitly specified message id...
            mimeMessage.setHeader(HEADER_MESSAGE_ID, messageId);
          }
          transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
        }
        catch (MessagingException ex) {
          Object original = (originalMessages != null ? originalMessages[i] : mimeMessage);
          failedMessages.put(original, ex);
        }
      }
    }
    finally {
      try {
        transport.close();
      }
      catch (MessagingException ex) {
        if (!failedMessages.isEmpty()) {
          throw new MailSendException("Failed to close server connection after message failures", ex,
              failedMessages);
        }
        else {
          throw new MailSendException("Failed to close server connection after message sending", ex);
        }
      }
    }

    if (!failedMessages.isEmpty()) {
      throw new MailSendException(failedMessages);
    }
  }
View Full Code Here

            // Effectively, all remaining messages failed...
            for (int j = i; j < mimeMessages.length; j++) {
              Object original = (originalMessages != null ? originalMessages[j] : mimeMessages[j]);
              failedMessages.put(original, ex);
            }
            throw new MailSendException("Mail server connection failed", ex, failedMessages);
          }
        }

        // Send message via current transport...
        MimeMessage mimeMessage = mimeMessages[i];
        try {
          if (mimeMessage.getSentDate() == null) {
            mimeMessage.setSentDate(new Date());
          }
          String messageId = mimeMessage.getMessageID();
          mimeMessage.saveChanges();
          if (messageId != null) {
            // Preserve explicitly specified message id...
            mimeMessage.setHeader(HEADER_MESSAGE_ID, messageId);
          }
          transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
        }
        catch (Exception ex) {
          Object original = (originalMessages != null ? originalMessages[i] : mimeMessage);
          failedMessages.put(original, ex);
        }
      }
    }
    finally {
      try {
        if (transport != null) {
          transport.close();
        }
      }
      catch (Exception ex) {
        if (!failedMessages.isEmpty()) {
          throw new MailSendException("Failed to close server connection after message failures", ex,
              failedMessages);
        }
        else {
          throw new MailSendException("Failed to close server connection after message sending", ex);
        }
      }
    }

    if (!failedMessages.isEmpty()) {
      throw new MailSendException(failedMessages);
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.mail.MailSendException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.