先是抄ibm网站上的一个例子,不成功,又加了验证,还是不行,请指点,谢谢编绎报错如下:
2005-10-22 16:10:11 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders警告: Cookie rejected: "HMSatchmo=1". Illegal domain attribute ".hotmail.com". Domain of origin: "services.msn.com"2005-10-22 16:10:11 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders警告: Cookie rejected: "HMMS2954=7AECB06078A51CDF473C412023A87595BCCAA425B558A226D883AF60D0956D90". Illegal domain attribute ".hotmail.com". Domain of origin: "services.msn.com"2005-10-22 16:10:11 org.apache.commons.httpclient.HttpMethodBase processRedirectResponse信息: Redirect requested but followRedirects is disabled2005-10-22 16:10:13 org.apache.commons.httpclient.HttpMethodBase processRedirectResponse信息: Redirect requested but followRedirects is disabled2005-10-22 16:10:14 org.apache.commons.httpclient.HttpMethodBase processRedirectResponse信息: Redirect requested but followRedirects is disabled2005-10-22 16:10:40 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders警告: Cookie rejected: "HMSatchmo=1". Illegal domain attribute ".hotmail.com". Domain of origin: "services.msn.com"2005-10-22 16:10:40 org.apache.commons.httpclient.HttpMethodBase processResponseHeaders警告: Cookie rejected: "HMMS2954=7AECB06078A51CDF473C412023A87595BCCAA425B558A238D883AF60D0956D90". Illegal domain attribute ".hotmail.com". Domain of origin: "services.msn.com"2005-10-22 16:10:40 org.apache.commons.httpclient.HttpMethodBase processRedirectResponse信息: Redirect requested but followRedirects is disabled2005-10-22 16:10:42 org.apache.commons.httpclient.HttpMethodBase processRedirectResponse信息: Redirect requested but followRedirects is disabled2005-10-22 16:10:46 org.apache.commons.httpclient.HttpMethodBase processRedirectResponse信息: Redirect requested but followRedirects is disabledjavax.mail.AuthenticationFailedException at javax.mail.Service.connect(Service.java:265) at javax.mail.Service.connect(Service.java:135) at jmail.Untitled3.main(Untitled3.java:34)=============================
MyAuth.java
------------------
package jmail;import javax.mail.Authenticator;
import javax.mail.* ;
import javax.mail.internet.*;public class MyAuth extends Authenticator {
  String username = null;
  String password = null;
  public MyAuth() {}  public PasswordAuthentication performCheck(String user, String pass) {
    username = user;
    password = pass;
    return getPasswordAuthentication();
  }  protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(username, password);
  }}
============================================================================
package jmail;import java.util.Date;
import java.util.Properties;import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.PasswordAuthentication;
public class Untitled3 {
  public Untitled3() {
  }
  public static void main(String[] args) {
    try {
                   Properties prop = new Properties();
                   //邮件发送者地址
                   prop.setProperty("mail.davmail.from","[email protected]");
                   prop.put("mail.smtp.autho","true");
                   
                   MyAuth auth = new MyAuth() ;
                   auth.performCheck("[email protected]","javadiannetpwd") ;
                   Session ses = Session.getInstance(prop,auth);
                   //获得JDAVMail的邮件发送实例
   Transport transport = ses.getTransport("davmail_xmit");
                   //连接到Hotmail服务器,请替换为自己的用户名和口令
                   transport.connect(null, "[email protected]","javadiannetpwd");                   // 准备要发送的邮件
                   MimeMessage txMsg = new MimeMessage(ses);
                   txMsg.setSubject("This is the subject");                   //邮件发送者地址
                   InternetAddress addrFrom = new InternetAddress("[email protected]");
                   txMsg.setFrom(addrFrom);                   //邮件接收者地址
                   InternetAddress addrTo = new InternetAddress("[email protected]");
                   txMsg.addRecipient(Message.RecipientType.TO, addrTo);                   //邮件内容
                   txMsg.setText("Hello world !");
                   txMsg.setSentDate(new Date());                   //发送邮件
                   transport.sendMessage(txMsg, txMsg.getAllRecipients());
           } catch (Exception ex) {
                   ex.printStackTrace();
           }  }}