全部代码如下:
package emailPack;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import java.io.*;
import java.net.Authenticator;
import java.util.*;
public class sendEmail {
public void sendMessage(){
Authenticator auth = new PopupAuthenticator();--------------------------------(1)
Properties mailProps = new Properties();
mailProps.put("mail.smtp.host", "smtp.163.com");
mailProps.put("mail.smtp.auth", "true");
mailProps.put("username", "pyrgz");
mailProps.put("password", "123456789");
Session mailSession = Session.getDefaultInstance(mailProps, auth);------------(2)
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(
"[email protected]"));
message.setSubject("Mail Test");
MimeMultipart multi = new MimeMultipart();
BodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setText("Hello World!");
multi.addBodyPart(textBodyPart);
message.setContent(multi);
message.saveChanges();
Transport.send(message);
    }
}为什么标记为(1)的代码报错:PopupAuthenticator can not be resolved to a type
请各位指点迷津。

解决方案 »

  1.   

    该类未导入,相关jar包导入并构建了没?
      

  2.   

    靠,你就没有写那个PopupAuthenticator类
    你要自己写这个类然后继承Authenticator 
    例如这样import javax.mail.Authenticator;  
    import javax.mail.PasswordAuthentication;  
    /** 
     * Smtp认证  
     * @author Administrator 
     * 
     */  
    public class MyAuthenticator extends Authenticator {  
        String username = null;    
        String password = null;    
        /**  
         * SMTP身份验证  
         * @param username  
         * @param password  
         */    
        public MyAuthenticator(String username, String password) {    
            super();    
            this.username = username;    
            this.password = password;    
        }    
        /**  
         * @return pass  
         */    
        public PasswordAuthentication getPasswordAuthentication() {    
            return new PasswordAuthentication(this.username, this.password);    
        }    
    }     
      

  3.   

    这篇文章你看看
    里面有源码
    http://blog.csdn.net/voyage_mh1987/archive/2010/08/03/5784191.aspx