Top Description Fields Constructors Methods
org.springframework.mail

public Class MailSendException

extends MailException
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
java.io.PrintStream, .PrintWriter, java.util.LinkedHashMap, .Map, org.springframework.lang.Nullable, org.springframework.util.ObjectUtils

Exception thrown when a mail sending error is encountered. Can register failed messages with their exceptions.
Authors
Dmitriy Kopylenko, Juergen Hoeller

Field Summary

Modifier and TypeField and Description
private final transient Map<Object, Exception>
private final Exception[]

Constructor Summary

AccessConstructor and Description
public
MailSendException(String
the detail message
msg
)

Constructor for MailSendException.

public
MailSendException(String
the detail message
msg
,
Throwable
the root cause from the mail API in use
cause
)

Constructor for MailSendException.

public
MailSendException(String
the detail message
msg
,
Throwable
the root cause from the mail API in use
cause
,
Map<Object, Exception>
a Map of failed messages as keys and thrown exceptions as values
failedMessages
)

Constructor for registration of failed messages, with the messages that failed as keys, and the thrown exceptions as values.

public
MailSendException(Map<Object, Exception>
a Map of failed messages as keys and thrown exceptions as values
failedMessages
)

Constructor for registration of failed messages, with the messages that failed as keys, and the thrown exceptions as values.

Method Summary

Modifier and TypeMethod and Description
public final Map<Object, Exception>

Returns:

the Map of failed messages as keys and thrown exceptions as values
getFailedMessages
()

Return a Map with the failed messages as keys, and the thrown exceptions as values.

public String
getMessage()

Overrides java.lang.Throwable.getMessage.

Returns the detail message string of this throwable.

public final Exception[]

Returns:

the array of thrown message exceptions, or an empty array if no failed messages
getMessageExceptions
()

Return an array with thrown message exceptions.

public void
printStackTrace(PrintStream
PrintStream to use for output
ps
)

Overrides java.lang.Throwable.printStackTrace.

Prints this throwable and its backtrace to the specified print stream.

public void
printStackTrace(PrintWriter
PrintWriter to use for output
pw
)

Overrides java.lang.Throwable.printStackTrace.

Prints this throwable and its backtrace to the specified print writer.

public String
toString()

Overrides java.lang.Throwable.toString.

Returns a short description of this throwable.

Field Detail

failedMessagesback to summary
private final transient Map<Object, Exception> failedMessages
messageExceptionsback to summary
private final Exception[] messageExceptions
Annotations
@Nullable

Constructor Detail

MailSendExceptionback to summary
public MailSendException(String msg)

Constructor for MailSendException.

Parameters
msg:String

the detail message

MailSendExceptionback to summary
public MailSendException(String msg, Throwable cause)

Constructor for MailSendException.

Parameters
msg:String

the detail message

cause:Throwable

the root cause from the mail API in use

MailSendExceptionback to summary
public MailSendException(String msg, Throwable cause, Map<Object, 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:String

the detail message

cause:Throwable

the root cause from the mail API in use

failedMessages:Map<Object, Exception>

a Map of failed messages as keys and thrown exceptions as values

MailSendExceptionback to summary
public MailSendException(Map<Object, 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<Object, Exception>

a Map of failed messages as keys and thrown exceptions as values

Method Detail

getFailedMessagesback to summary
public final Map<Object, 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:Map<Object, Exception>

the Map of failed messages as keys and thrown exceptions as values

See Also
SimpleMailMessage, jakarta.mail.internet.MimeMessage
getMessageback to summary
public String getMessage()

Overrides java.lang.Throwable.getMessage.

Doc from java.lang.Throwable.getMessage.

Returns the detail message string of this throwable.

Returns:String

the detail message string of this Throwable instance (which may be null).

Annotations
@Override
@Nullable
getMessageExceptionsback to summary
public final 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:Exception[]

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

printStackTraceback to summary
public void printStackTrace(PrintStream ps)

Overrides java.lang.Throwable.printStackTrace.

Doc from java.lang.Throwable.printStackTrace.

Prints this throwable and its backtrace to the specified print stream.

Parameters
ps:PrintStream

PrintStream to use for output

Annotations
@Override
printStackTraceback to summary
public void printStackTrace(PrintWriter pw)

Overrides java.lang.Throwable.printStackTrace.

Doc from java.lang.Throwable.printStackTrace.

Prints this throwable and its backtrace to the specified print writer.

Parameters
pw:PrintWriter

PrintWriter to use for output

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Throwable.toString.

Doc from java.lang.Throwable.toString.

Returns a short description of this throwable. The result is the concatenation of:

  • the name of the class of this object
  • ": " (a colon and a space)
  • the result of invoking this object's getLocalizedMessage method
If getLocalizedMessage returns null, then just the class name is returned.
Returns:String

a string representation of this throwable.

Annotations
@Override