javax.mail.getValidSentAddresses()

javax.mail.getValidSentAddresses()

我更新了我的代码:

1) 我添加了以下属性:

        Properties props=new Properties();
        props.put(smtp,host);
        props.put("mail.smtp.reportsuccess","true");
        props.put("mail.smtp.sendpartial", "true");

然后按照答案中的指示编写此块:

        }catch (MessagingException mex){   

        Exception ex = mex;

            do {
                if(ex instanceof SendFailedException) {
                SendFailedException sfe = (SendFailedException) ex;

                Address[] vsa   = sfe.getValidSentAddresses();                                  
                Address[] vua   = sfe.getValidUnsentAddresses();
                Address[] ia    = sfe.getInvalidAddresses();

                if(vsa !=null || vsa.length>0){
                    String validSentAddresses = vsa[0].toString();              
                    printReport("GSWvalidSentAddresses.txt", validSentAddresses);
                }
                else if(vua !=null || vua.length>0){
                    String validUnsentAddresses = vua[0].toString();
                    printReport("GSWvalidUnsentAddresses.txt", validUnsentAddresses);
                }
                else if(ia !=null || ia.length>0){              
                    String invalidAddresses = ia[0].toString();
                    printReport("GSWinvalidAddresses.txt", invalidAddresses);
                }
                else{}                                      
                        if (ex instanceof MessagingException)
                        ex = ((MessagingException) ex).getNextException();
                    else
                        ex = null;
                }// 
            } while (ex != null);
    }//main catch block     
    }

当它运行 抛出 504 网关超时时--------nginx

请指教

感谢期待

设置mail.smtp.reportsuccess session property to true. This will cause Transport.send to always throw SendFailedException。根据文档:

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, an SMTPAddressSucceededException 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.

使用'chained'这个词意味着你必须调用MessagingException.getNextException()

您还感兴趣的是 'mail.smtp.sendpartial' 属性,它也包含在文档中。

您还应该更改代码以使用 Session.getInstance