org.springframework.mail
Class MailSendException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.lang.RuntimeException
              extended by org.springframework.core.NestedRuntimeException
                  extended by org.springframework.mail.MailException
                      extended by org.springframework.mail.MailSendException
All Implemented Interfaces:
java.io.Serializable

public class MailSendException
extends MailException

Exception thrown when a mail sending error is encountered. Can register failed messages with their exceptions.

Author:
Dmitriy Kopylenko, Juergen Hoeller
See Also:
Serialized Form

Field Summary
private  java.util.Map<java.lang.Object,java.lang.Exception> failedMessages
           
private  java.lang.Exception[] messageExceptions
           
 
Constructor Summary
MailSendException(java.util.Map<java.lang.Object,java.lang.Exception> failedMessages)
          Constructor for registration of failed messages, with the messages that failed as keys, and the thrown exceptions as values.
MailSendException(java.lang.String msg)
          Constructor for MailSendException.
MailSendException(java.lang.String msg, java.lang.Throwable cause)
          Constructor for MailSendException.
MailSendException(java.lang.String msg, java.lang.Throwable cause, java.util.Map<java.lang.Object,java.lang.Exception> failedMessages)
          Constructor for registration of failed messages, with the messages that failed as keys, and the thrown exceptions as values.
 
Method Summary
 java.util.Map<java.lang.Object,java.lang.Exception> getFailedMessages()
          Return a Map with the failed messages as keys, and the thrown exceptions as values.
 java.lang.String getMessage()
          Return the detail message, including the message from the nested exception if there is one.
 java.lang.Exception[] getMessageExceptions()
          Return an array with thrown message exceptions.
 void printStackTrace(java.io.PrintStream ps)
           
 void printStackTrace(java.io.PrintWriter pw)
           
 java.lang.String toString()
           
 
Methods inherited from class org.springframework.core.NestedRuntimeException
contains, getMostSpecificCause, getRootCause
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, initCause, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

failedMessages

private final transient java.util.Map<java.lang.Object,java.lang.Exception> failedMessages

messageExceptions

private java.lang.Exception[] messageExceptions
Constructor Detail

MailSendException

public MailSendException(java.lang.String msg)
Constructor for MailSendException.

Parameters:
msg - the detail message

MailSendException

public MailSendException(java.lang.String msg,
                         java.lang.Throwable cause)
Constructor for MailSendException.

Parameters:
msg - the detail message
cause - the root cause from the mail API in use

MailSendException

public MailSendException(java.lang.String msg,
                         java.lang.Throwable cause,
                         java.util.Map<java.lang.Object,java.lang.Exception> failedMessages)
Constructor for registration of failed messages, with the messages that failed as keys, and the thrown exceptions as values.

The messages should be the same that were originally passed to the invoked send method.

Parameters:
msg - the detail message
cause - the root cause from the mail API in use
failedMessages - Map of failed messages as keys and thrown exceptions as values

MailSendException

public MailSendException(java.util.Map<java.lang.Object,java.lang.Exception> failedMessages)
Constructor for registration of failed messages, with the messages that failed as keys, and the thrown exceptions as values.

The messages should be the same that were originally passed to the invoked send method.

Parameters:
failedMessages - Map of failed messages as keys and thrown exceptions as values
Method Detail

getFailedMessages

public final java.util.Map<java.lang.Object,java.lang.Exception> getFailedMessages()
Return a Map with the failed messages as keys, and the thrown exceptions as values.

Note that a general mail server connection failure will not result in failed messages being returned here: A message will only be contained here if actually sending it was attempted but failed.

The messages will be the same that were originally passed to the invoked send method, that is, SimpleMailMessages in case of using the generic MailSender interface.

In case of sending MimeMessage instances via JavaMailSender, the messages will be of type MimeMessage.

NOTE: This Map will not be available after serialization. Use getMessageExceptions() in such a scenario, which will be available after serialization as well.

Returns:
the Map of failed messages as keys and thrown exceptions as values
See Also:
SimpleMailMessage, javax.mail.internet.MimeMessage

getMessageExceptions

public final java.lang.Exception[] getMessageExceptions()
Return an array with thrown message exceptions.

Note that a general mail server connection failure will not result in failed messages being returned here: A message will only be contained here if actually sending it was attempted but failed.

Returns:
the array of thrown message exceptions, or an empty array if no failed messages

getMessage

public java.lang.String getMessage()
Description copied from class: NestedRuntimeException
Return the detail message, including the message from the nested exception if there is one.

Overrides:
getMessage in class NestedRuntimeException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Throwable

printStackTrace

public void printStackTrace(java.io.PrintStream ps)
Overrides:
printStackTrace in class java.lang.Throwable

printStackTrace

public void printStackTrace(java.io.PrintWriter pw)
Overrides:
printStackTrace in class java.lang.Throwable