pop3 跟smtp 都设置了.25 110 端口 路由的映射也做了.telnet 配置正常, 邮件发送都正常,服务器端接收也正常,就是客户端接收邮件时报错;
用javamail 读取时异常:Exception in thread "main" javax.mail.AuthenticationFailedException: SPA Required, use AUTH or APOP
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:104)
at javax.mail.Service.connect(Service.java:233)
at javax.mail.Service.connect(Service.java:134)
at javax.mail.Service.connect(Service.java:86)
at com.demo.javamail.ReciveOneMail.main(ReciveOneMail.java:345)
用foxmail 也是一样的错误信息
[b]问题补充:[/b]
找到原因了,是pop3 提供的spa 验证 javamail 跟foxmail 都不支持造成的 - -! 取掉pop3的 spa验证就可以了;
但是现在有个问题就是,去了spa验证,这个貌似会有安全问题,哪位着方面的经验...给指点指点...
// Setup properties
Properties props = System.getProperties();
props.put("mail.pop3.host", host);
// Setup authentication, get session
Authenticator auth = new PopupAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
// Get the store
Store store = session.getStore("pop3");
store.connect();
然后,您创建一个 Authenticator 子类并从 getPasswordAuthentication() 方法中返回 PasswordAuthentication 对象。下面就是这样一种实现,其中用户名和密码仅占用一个域。(这不是一个 Swing 工程教程;只要将两部分输入同一个域,用逗号分隔就行。)
import javax.mail.*;
import javax.swing.*;
import java.util.*;
public class PopupAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
String username, password;
String result = JOptionPane.showInputDialog(
"Enter 'username,password'");
StringTokenizer st = new StringTokenizer(result, ",");
username = st.nextToken();
password = st.nextToken();
return new PasswordAuthentication(username, password);
}
}
从别人那里考一段代码过来,你自己参考吧。自己在网上找一下,javamail这种东西都被大家用滥了,基本你碰到的问题,前人都碰到过。
AuthenticationFailedException, 这不是明显是需要认证用户,也就是要先登录,才能接收邮件,是不是没有处理这个部分,还是用户名和密码搞错了?