项目需要集成邮件发送,之前在.net下写过smtp的邮件发送,好像可以直接获取状态码。在网上找到的javamail发送例子中并未给出如何获取状态码。而且sendMessage方法直接是void没任何返回参数。
之后在查阅api时终于有所发现
When sending a message, detailed information on each address that fails is available in an SMTPAddressFailedException
chained off the top level SendFailedException
that is thrown. In addition, if the mail.smtp.reportsuccess
property is set, anSMTPAddressSucceededException
will be included in the list for each address that is successful. Note that this will cause a top level SendFailedException
to be thrown even though the send was successful.
SMTPAddressFailedException 和
SMTPAddressSucceededException 中就包含了状态码
以作备注,希望下次再遇到问题的时候自己能搜到。