Exchange Server 2010 からメールを読み取ろうとしていますが、接続が確立されることもありますが、残りの時間はプログラムで以下の例外が発生します。
javax.mail.AuthenticationFailedException: ログインに失敗しました
コードは Exchange Server 2007 で正常に動作しています。しかし、メールボックスが 2010 に移行された時点から、プログラムはこの方法でのみ動作しています。
ネットで利用可能ないくつかのオプションも試しましたが、何も機能していません。javamail-1.4.4 API バージョンを使用しています。これは、メールボックスに接続しようとしているコードです。
public class ReadMail {
static Store store=null;
static String host="";
static String username="";
static String password="";
public static void main(String[] arg) throws Exception{
try{
Session session;
username = "username";
password = "password";
host = "hostname";
Properties props = System.getProperties();
props.setProperty("mail.smtp.auth","true");
session = Session.getInstance(props,
new ExchangeAuthenticator(username, password));
Store st = session.getStore("imaps");
st.connect(host,username, password);
System.out.println("Connected");
}
catch (Exception e){
e.printStackTrace(System.out);
}
}
}
public class ExchangeAuthenticator extends Authenticator {
String user;
String pw;
public ExchangeAuthenticator (String username, String password)
{
super();
this.user = username;
this.pw = password;
}
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(user, pw);
}
}