javax.mail.AuthenticationFailedException
发送邮件出现这个异常是为什么呢?是验证没有通过吗?
可是我用IE登陆邮箱的时候  都能登陆上去的啊

解决方案 »

  1.   

    QQ 的  和 sina 的 我都尝试了   都是这个异常....
      

  2.   

    认证参数?
    指的是那个 stmp.qq.com  smtp.sina.com
    这个吗?
    我都有 对比过的   下面是我写的代码  请帮忙看下
    Properties props = new Properties();
                props.put("mail.smtp.host", "smtp.sina.com");
                props.put("mail.smtp.port", "25");
                props.put("mail.smtp.auth", "true");            SuperAuthenticator ma = new SuperAuthenticator("my邮箱", "密码");
                Session mailSession = Session.getDefaultInstance(props, ma);
                mailSession.setDebug(true);
                Message message = new MimeMessage(mailSession);            message.setFrom(new InternetAddress("my邮箱"));
                message.setRecipient(Message.RecipientType.TO,
                                     new InternetAddress("to邮箱"));
                message.setSubject("haha");
                message.setText("text");
                message.saveChanges();
    Transport.send(message);
      

  3.   

    老代码,看能不能帮到楼主,
    不保证能用呀 if (needAuth){
    props.put("mail.smtp.auth", "true");
    Authenticator auth = new MyPasswordAuthentication().getInstance(name,password); session = Session.getDefaultInstance(props, auth);// 创建session
    }else{
    props.put("mail.smtp.auth", "false");
    session = Session.getDefaultInstance(props, null);
    }
    class MyPasswordAuthentication extends Authenticator {

    public MyPasswordAuthentication() { // TODO Auto-generated constructor stub
    } String username = null; String password = null; PasswordAuthentication pa = null; public static MyPasswordAuthentication instance = null; public static synchronized MyPasswordAuthentication getInstance(String user, String pass) {
    if (instance == null) {
    instance = new MyPasswordAuthentication(user, pass);
    }
    return instance;
    } public MyPasswordAuthentication(String user, String pass) {
    username = user;
    password = pass;
    } public PasswordAuthentication getPasswordAuthentication() { if (pa == null) {
    pa = new PasswordAuthentication(username, password);
    } return pa;
    }
    }
      

  4.   

    javaMail连接商业邮箱,163的可以,yahoo和gmail好像都不行。其他没有试过。
    不过即使是连接163,也是需要用有密码的方式连接。附上我自己正在用的代码。XXXX等是个人信息。能发信,收信没有做。package com.XXXXXX.common.mail;import java.util.Properties;import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.AddressException;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;public class BaseMailMessage { protected Session mailSession; public BaseMailMessage() {
    /* 初始化服务器环境 */
    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.host", "smtp.163.com");
    props.put("mail.smtp.port", "25");
    props.put("mail.user", "XXXXXX");
    props.put("mail.password", "XXXXX");
    props.put("mail.from", "XXXXXXXXXXX");
    props.put("mail.smtp.auth", "true");
    mailSession = Session.getDefaultInstance(props, null);
    } public boolean sendMail(String to, String cc, String bcc, String title,
    String text) {
    Message msg = new MimeMessage(mailSession);
    Properties props = mailSession.getProperties();
    Transport transport = null;
    try {
    msg.setFrom(new InternetAddress((String) props.get("mail.from"))); msg.setRecipients(Message.RecipientType.TO, InternetAddress
    .parse(to));
    if (cc != null) {
    msg.setRecipients(Message.RecipientType.CC, InternetAddress
    .parse(cc));
    }
    if (bcc != null) {
    msg.setRecipients(Message.RecipientType.BCC, InternetAddress
    .parse(bcc));
    }
    msg.setSentDate(new java.util.Date());
    msg.setSubject(title);
    msg.setText(text); if (props.get("mail.user") == null) {
    Transport.send(msg);
    } else { transport = mailSession.getTransport("smtp");
    transport.connect((String) props.get("mail.smtp.host"),
    (String) props.get("mail.user"), (String) props
    .get("mail.password"));
    transport.sendMessage(msg, msg
    .getRecipients(Message.RecipientType.TO));
    if (cc != null) {
    transport.sendMessage(msg, msg
    .getRecipients(Message.RecipientType.CC));
    }
    if (bcc != null) {
    transport.sendMessage(msg, msg
    .getRecipients(Message.RecipientType.BCC));
    }
    }
    return true;
    } catch (AddressException e1) {
    return false;
    } catch (MessagingException e1) {
    return false;
    } finally {
    if (transport != null) {
    try {
    transport.close();
    } catch (MessagingException e) {
    ;
    }
    }
    }
    } public boolean sendMail(String to, String title, String text) {
    return sendMail(to, null, null, title, text);
    }
    }