Package javax.mail

Examples of javax.mail.SendFailedException


        if ( isNullOrEmpty((Object[]) addresses)
                && isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.TO))
                && isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.CC))
                && isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.BCC)) ) {
            throw new SendFailedException("No recipient addresses");
        }

        // Make sure all addresses are internet addresses
        Set<Address> invalid = new HashSet<Address>();
        for ( Address[] recipients : new Address[][] {
                m.getRecipients(Message.RecipientType.TO),
                m.getRecipients(Message.RecipientType.CC),
                m.getRecipients(Message.RecipientType.BCC),
                addresses } ) {
            if ( !isNullOrEmpty(recipients) ) {
                for ( Address a : recipients ) {
                    if ( !(a instanceof InternetAddress) ) {
                        invalid.add(a);
                    }
                }
            }
        }

        if ( !invalid.isEmpty() ) {
            Address[] sent = new Address[0];
            Address[] unsent = new Address[0];
            super.notifyTransportListeners(TransportEvent.MESSAGE_NOT_DELIVERED, sent, unsent,
                    invalid.toArray(new Address[invalid.size()]), m);
            throw new SendFailedException("AWS Mail Service can only send to InternetAddresses");
        }
    }
View Full Code Here


      unsent = m.getAllRecipients();
      invalid = new Address[0];
      super.notifyTransportListeners(
          TransportEvent.MESSAGE_NOT_DELIVERED, sent, unsent,
          invalid, m);
      throw new SendFailedException("Unable to send email", e, sent,
          unsent, invalid);
    }
  }
View Full Code Here

      logger.info("Preparing to send message");
      Transport.send(mimeMessage);
      logger.info("Message Sent!");
    } catch (MessagingException e) {
      logger.error("Error sending message.", e);
      throw new SendFailedException("Send Failed", e);
    }
  }
View Full Code Here

      mex.printStackTrace();
      Exception ex = mex;
      do {
        if (ex instanceof SendFailedException) {
          SendFailedException sfex = (SendFailedException) ex;
          Address[] invalid = sfex.getInvalidAddresses();
          if (invalid != null) {
            log4j.error("    ** Invalid Addresses");
            sb.append("    ** Invalid Addresses\n");
            if (invalid != null) {
              for (int i = 0; i < invalid.length; i++) {
                log4j.error("         " + invalid[i]);
                sb.append("         " + invalid[i] + "\n");
              }
            }
          }
          Address[] validUnsent = sfex.getValidUnsentAddresses();
          if (validUnsent != null) {
            log4j.error("    ** ValidUnsent Addresses");
            sb.append("    ** ValidUnsent Addresses\n");
            if (validUnsent != null) {
              for (int i = 0; i < validUnsent.length; i++) {
                log4j.error("         " + validUnsent[i]);
                sb.append("         " + validUnsent[i] + "\n");
              }
            }
          }
          Address[] validSent = sfex.getValidSentAddresses();
          if (validSent != null) {
            log4j.error("    ** ValidSent Addresses");
            sb.append("    ** ValidSent Addresses\n");
            if (validSent != null) {
              for (int i = 0; i < validSent.length; i++) {
View Full Code Here

     */
    private String exceptionToLogString(Exception e) {
        if (e.getClass().getName().endsWith(".SMTPSendFailedException")) {
            return "RemoteHost said: " + e.getMessage();
        } else if (e instanceof SendFailedException) {
            SendFailedException exception = (SendFailedException) e;

            // No error
            if (exception.getInvalidAddresses().length == 0 && exception.getValidUnsentAddresses().length == 0)
                return null;

            Exception ex;
            StringBuilder sb = new StringBuilder();
            boolean smtpExFound = false;
            sb.append("RemoteHost said:");

            if (e instanceof MessagingException)
                while ((ex = ((MessagingException) e).getNextException()) != null && ex instanceof MessagingException) {
                    e = ex;
                    if (ex.getClass().getName().endsWith(".SMTPAddressFailedException")) {
                        try {
                            InternetAddress ia = (InternetAddress) invokeGetter(ex, "getAddress");
                            sb.append(" ( ").append(ia).append(" - [").append(ex.getMessage().replaceAll("\\n", "")).append("] )");
                            smtpExFound = true;
                        } catch (IllegalStateException ise) {
                            // Error invoking the getAddress method
                        } catch (ClassCastException cce) {
                            // The getAddress method returned something
                            // different than InternetAddress
                        }
                    }
                }
            if (!smtpExFound) {
                boolean invalidAddr = false;
                sb.append(" ( ");

                if (exception.getInvalidAddresses().length > 0) {
                    sb.append(Arrays.toString(exception.getInvalidAddresses()));
                    invalidAddr = true;
                }
                if (exception.getValidUnsentAddresses().length > 0) {
                    if (invalidAddr)
                        sb.append(" ");
                    sb.append(Arrays.toString(exception.getValidUnsentAddresses()));
                }
                sb.append(" - [");
                sb.append(exception.getMessage().replaceAll("\\n", ""));
                sb.append("] )");
            }
            return sb.toString();
        }
        return null;
View Full Code Here

      
        if ( isNullOrEmpty((Object[]) addresses)
                && isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.TO))
                && isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.CC))
                && isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.BCC)) ) {
            throw new SendFailedException("No recipient addresses");
        }

        // Make sure all addresses are internet addresses
        Set<Address> invalid = new HashSet<Address>();
        for ( Address[] recipients : new Address[][] {
                m.getRecipients(Message.RecipientType.TO),
                m.getRecipients(Message.RecipientType.CC),
                m.getRecipients(Message.RecipientType.BCC),
                addresses } ) {
            if ( !isNullOrEmpty(recipients) ) {
                for ( Address a : recipients ) {
                    if ( !(a instanceof InternetAddress) ) {
                        invalid.add(a);
                    }
                }
            }
        }
       
        if ( !invalid.isEmpty() ) {
            Address[] sent = new Address[0];
            Address[] unsent = new Address[0];
            super.notifyTransportListeners(TransportEvent.MESSAGE_NOT_DELIVERED, sent, unsent,
                    invalid.toArray(new Address[invalid.size()]), m);
            throw new SendFailedException("AWS Mail Service can only send to InternetAddresses");
        }
    }
View Full Code Here

      unsent = m.getAllRecipients();
      invalid = new Address[0];
      super.notifyTransportListeners(
          TransportEvent.MESSAGE_NOT_DELIVERED, sent, unsent,
          invalid, m);
      throw new SendFailedException("Unable to send email", e, sent,
          unsent, invalid);
    }
  }
View Full Code Here

Email e = new Email();
    e.setText("This is a test!");
    e.setSubject("JWIG email test");
    e.setSender(new InternetAddress("unknown@example.org"));
    e.addRecipients(Message.RecipientType.TO, "amoeller@cs.au.dk");
    SendFailedException ex = sendEmail(e);
    if ((ex == null)) return "Email sent!";
    else return ex.toString();
   
   
}
View Full Code Here

    // First collect all the addresses together.
        Address[] remainingAddresses = message.getAllRecipients();
        int nAddresses = remainingAddresses.length;
        boolean bFailedToSome = false;
       
        SendFailedException sendex = new SendFailedException("Unable to send message to some recipients");
       
    // Try to send while there remain some potentially good addresses
    do
        {
      // Avoid a loop if we are stuck
      nAddresses = remainingAddresses.length;

      try
      {
        // Send to the list of remaining addresses, ignoring the addresses attached to the message
            Transport.send(message,remainingAddresses);
      }
      catch(SendFailedException ex)
      {
        bFailedToSome=true;
        sendex.setNextException(ex);
       
        // Extract the remaining potentially good addresses
        remainingAddresses=ex.getValidUnsentAddresses();
      }
        } while (remainingAddresses!=null && remainingAddresses.length>0 && remainingAddresses.length!=nAddresses);
View Full Code Here

TOP

Related Classes of javax.mail.SendFailedException

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.