0
私はアカウントから電子メールを送信するためのシンプルなjavamailクライアントを作成しています。私は認証失敗を聞きたいので、適切なメッセージを表示することができます。 Transportオブジェクトを使用して接続リスナーを追加しようとしています。私はコンソールで私がエラーを取得していることがわかりますが、私は "addConnectionListener()"に割り当てているオブジェクトはそれをピックアップしていません。サンプルコード:JavaMail APIを使用して認証エラーをどのようにリスンしますか?
mSession = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(CustomMailSender.this.mUser, CustomMailSender.this.mPassword);
}
});
mTransport = mSession.getTransport(protocol);
mTransport.addConnectionListener(new ConnectionListener() {
@Override
public void opened(ConnectionEvent e) {
Timber.e(" connection opened");
}
@Override
public void disconnected(ConnectionEvent e) {
Timber.e(" connection disconnected");
}
@Override
public void closed(ConnectionEvent e) {
Timber.e(" connection closed");
}
});
int iPort = Integer.parseInt(port);
mTransport.connect(mMailHost,iPort , user, password);
私はここにメッセージを送信しています私が接続しようとする試みが失敗した場合、それは「切断」でも引き金だろうと予想していた
mTransport.sendMessage(message, InternetAddress.parse(recipients));
?
AuthenticationFailedExceptionはいつスローされますか? Session.getInstance()またはtransport.sendMessageまたはTransport.send()で取得できません。 – giulio
私が言ったように、それはconnectメソッドからスローされます。 –
ありがとう..申し訳ありませんが、かなり忙しく、正しく応答を読み込めません。 – giulio