这是我的代码:
package com.mail.test;import java.util.Properties;import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;public class Demo1 { /**
 * @param args add by zxx ,Feb 5, 2009
 */
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
Properties props = new Properties();
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.transport.protocol", "smtp");
Session session = Session.getInstance(props);
session.setDebug(true);

Message msg = new MimeMessage(session);
msg.setText("你好吗?");
msg.setFrom(new InternetAddress("[email protected]"));

Transport transport = session.getTransport();
transport.connect("smtp.sina.com", 25, "itcast_test", "123456");
transport.sendMessage(msg,
new Address[]{new InternetAddress("[email protected]")}); //transport.send(msg,new Address[]{new InternetAddress("[email protected]")});
transport.close();
}}前面一切正常但是运行到发送的时候老是报这个错误怎么办:
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.sina.com", port 25, isSSL false
220 irxd5-203.sinamail.sina.com.cn ESMTP
DEBUG SMTP: connected to host "smtp.sina.com", port: 25EHLO XP-200905041912
250-irxd5-203.sinamail.sina.com.cn
250-8BITMIME
250-SIZE 31457280
250-AUTH PLAIN LOGIN
250 AUTH=PLAIN LOGIN
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "31457280"
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "AUTH=PLAIN", arg "LOGIN"
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
aXRjYXN0X3Rlc3Q=
334 UGFzc3dvcmQ6
MTIzNDU2
535 #5.7.0 Authentication failed
Exception in thread "main" javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
at com.mail.test.Demo1.main(Demo1.java:30)

解决方案 »

  1.   

    你确定你的新浪用户名密码正确么?
    transport.connect("smtp.sina.com", 25, "itcast_test", "123456");
    这里貌似应该用你的新浪邮箱, 而不只是用户名. 试试[email protected] (也就是你的邮箱地址).
      

  2.   

    transport.connect("smtp.sina.com", 25, "itcast_test", "123456"); 
    我用了我自己的新浪邮箱可以。
    你的应该是smtp/pop没打开,需要自己在账户中打开。
    免费邮箱为了避免你这样发送垃圾邮件默认关闭了这个功能,需要自己手动打开。
      

  3.   

    试试将发件邮箱也改为sina的试试
      

  4.   

    AUTH LOGIN 
    334 VXNlcm5hbWU6 
    aXRjYXN0X3Rlc3Q= 
    334 UGFzc3dvcmQ6 
    MTIzNDU2 
    535 #5.7.0 Authentication failed 用户名或者密码错了
      

  5.   


    我也是新申请了sina邮箱,免费的,刚开始也是和lz一样的问题,后来看了2楼的解释,设置了邮箱,ok了。