Package javax.mail

Examples of javax.mail.SendFailedException


      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


      
        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

     */
    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(" ( " + ia + " - [" + ex.getMessage().replaceAll("\\n", "") + "] )");
                         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(exception.getInvalidAddresses());
                    invalidAddr = true;
                }
                if (exception.getValidUnsentAddresses().length > 0) {
                    if (invalidAddr == true) sb.append(" " );
                    sb.append(exception.getValidUnsentAddresses());
                }
                sb.append(" - [");
                sb.append(exception.getMessage().replaceAll("\\n", ""));
                sb.append("] )");
             }
             return sb.toString();
        }
        return null;
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

      
        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

        // 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");
       
        Transport transport = mailProvider.getTransport();
       
        // Try to send while there remain some potentially good addresses
        try {
            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.sendMessage(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

        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

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.