この質問が完全にカバーされているかどうかはわかりませんが、 SMTPTransport.javaをちらっと見たところ、次のように説明されgetReportSuccess()
ています。
/**
* Should we report even successful sends by throwing an exception?
* If so, a <code>SendFailedException</code> will always be thrown and
* an {@link com.sun.mail.smtp.SMTPAddressSucceededException
* SMTPAddressSucceededException} will be included in the exception
* chain for each successful address, along with the usual
* {@link com.sun.mail.smtp.SMTPAddressFailedException
* SMTPAddressFailedException} for each unsuccessful address.
*
* @return true if an exception will be thrown on successful sends.
*
* @since JavaMail 1.3.2
*/
public synchronized boolean getReportSuccess() {
return reportSuccess;
}
したがって、私のコードでは、送信プロセスが正常に完了したことを確認するために、setReportSuccess(true);
送信前に呼び出して例外を処理しましたcom.sun.mail.smtp.SMTPAddressSucceededException
。次のコード スニペットは問題なく機能します。
public synchronized void sendMail(String subject, String body, String user, String oauthToken, String recipients, String attachment)
{
try {
SMTPTransport smtpTransport = connectToSmtp("smtp.gmail.com", 587, user, oauthToken, true);
MimeMessage message = new MimeMessage(session);
/*Set whether successful sends should be reported by throwing
**an exception.
*/
smtpTransport.setReportSuccess(true);
/**
***All actions to got the formated message
**/
/*Send message*/
smtpTransport.sendMessage(message, message.getAllRecipients());
} catch(android.os.NetworkOnMainThreadException e){
Log.d("MY_LOG","NetworkOnMainThreadException");
}
catch(com.sun.mail.smtp.SMTPAddressSucceededException e){
/**
***Message has been sent. Do what you need.
**/
}
catch (Exception e) {
Log.d("MY_LOG", e.getMessage());
}
}