没有为java mail api中的getInstance错误找到合适的方法

时间:2013-11-14 10:05:45

标签: java email session javamail

我正在使用java mail api发送邮件但遇到以下错误..

no suitable method found for getInstance(java.util,Properties,java.net.Authenticator)

这是我在java中的代码片段。

 Authenticator auth = new Authenticator() {

        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(userName, password.toCharArray());
        }
    };
    Session session = Session.getInstance(properties, auth);

我在接下来的行中收到了上述错误。

Session session = Session.getInstance(properties, auth);

请帮帮我。 提前谢谢..

1 个答案:

答案 0 :(得分:3)

问题是您已导入java.net.Authenticator而不是javax.mail.Authenticator。查看错误消息中指定的类型,然后查看Session.getInstance文档中的参数类型。