We tried to send mail using javax.mail
. While sending mails we got following exception:
**sendMail - Message Sending Failed: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550 #5.1.0 Address rejected.2013-02-28 13:17:08,236**
What might be the problem?
It means that the receiving server does not recognise the mailbox (the part before the '@') of the e-mail address. It could be that it was misspelled, that it is simply a non-existing name, or it could even be that the receiving server was set to reject a message (e.g. spam) by replying with code 550.
Here is one of many pages that summarises the SMTP reply codes, and gives links to various relevant RFCs: http://www.greenend.org.uk/rjk/tech/smtpreplies.html.
EDIT: I need a bit more space to answer your question than the comments allow.
@RaghuKing, if you look at the Javadoc for javax.mail.SendFailedException
, you will notice that you can call 3 methods on such an exception object (inside the catch
block):
getInvalidAddresses()
to get an array of addresses that are invalid and thus not sent to,getValidSentAddresses()
to get an array of addresses to which this message was sent succesfully, andgetValidUnsentAddresses()
to get an array of addresses that are valid but to which the message was not sent to. (Obviously, if one sends a message to multiple recipients, some may succeed and some fail, but the exception is thrown if there is at least one failure, regardless of how many successes. Obviously also if you are sending to only one address, you will have that one address in only one of these arrays, and it will probably NOT be in the ValidSent list.
These arrays will give you more information how to handle the exception, depending of the type of array an address is in. This will obviously depend on you application, but these might be reasonable suggestions:
But in the end it is you who has to apply common sense, and perhaps experiment a little with the functions you don't understand until you understand them.