µ±½ñmail·þÎñÆ÷´ó¶à¶¼ÊÇͨ¹ýÈÏÖ¤²ÅÄÜ·¢Ðŵģ¬ÏÖÔÚµÄÍøÉϽéÉÜjavamail·¢ÐŵÄÎÄÕ¶¼Ã»ÓÐÉîÈëµ½ÓйØÈÏÖ¤µÄ·½Ã棬³ý·Ç×Ô¼º×°Ò»¸öopen¡¡relayµÄmail·þÎñÆ÷£¬µ«ÊÇÕâÑùÓкÜΣÏÕ£¬±¾È˸ù¾Ý×Ô¼º¹¤×÷ÖÐÓõÄjavamailµÄ·½·¨ËµÒ»ÏÂ×Ô¼ºµÄÓ÷¨£¬²»¶ÔµÄµØ·½Çë´ó¼Ò¶àÖ¸½Ì£®
¡¡¡¡Ê×ÏÈÉèÖÃÊôÐÔProperties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth","true");×¢ÒâµÄÊÇ´Ë´¦±ØÐë¼ÓÉÏtrueÒª²»È»stmpÁ¬½ÓµÄʱºò²»»áÈÏÖ¤
¡¡¡¡ÓÃAuthenticatorдÈÏÖ¤ÀàÏÂÃæÊDZ¾È˵ÄÈÏÖ¤Àà
package org.£ø£ø£ø;
import javax.mail.*;
import javax.mail.internet.*;
public class PopupAuthenticator extends Authenticator{
String username=null;
String password=null;
public PopupAuthenticator(){}
public PasswordAuthentication performCheck(String user,String pass){
username = user;
password = pass;
return getPasswordAuthentication();
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
}
ÈÏÖ¤ÀàдÍêºó£¬ÔÚ·¢ÐŵijÌÐòÖмÓÉÏ
PasswordAuthentication pop = popAuthenticator.performCheck(username,password);
Session mysession=Session.getInstance(props,popAuthenticator);
mailsession¼ÓµÄpopAuthenticator
ÆäËûµÄ·½·¨ºÍjavamail·¢ÐŵÄÓ÷¨ÏàËÆ£¬Ôڴ˲»ÀÛÊö¡£ ,