I'm not sure that it covers this question completely, but when I looked at SMTPTransport.java , the description of getReportSuccess() says
public synchronized boolean getReportSuccess() { return reportSuccess; }
So, in my code, to make sure the transfer process completed successfully, I called setReportSuccess(true); before sending, and then handled the com.sun.mail.smtp.SMTPAddressSucceededException exception. The following code snippet works fine for me:
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); smtpTransport.setReportSuccess(true); smtpTransport.sendMessage(message, message.getAllRecipients()); } catch(android.os.NetworkOnMainThreadException e){ Log.d("MY_LOG","NetworkOnMainThreadException"); } catch(com.sun.mail.smtp.SMTPAddressSucceededException e){ } catch (Exception e) { Log.d("MY_LOG", e.getMessage()); } }
source share