//props.put("mail.smtp.auth","true");
         // props.put("mail.smtp.user", "jb_china2004");
         //props.put("mail.smtp.password", "不能说");
把注释去掉,写一个授权类:
public class MyAuthenticator extends javax.mail.Authenticator
{
private String m_username = null;
private String m_userpass = null;public void setUsername(String username)
{
 m_username = username;
}public void setUserpass(String userpass)
{
 m_userpass = userpass;
}public MyAuthenticator (String username, String userpass)
{
   super();   setUsername(username);
   setUserpass(userpass);}
public PasswordAuthentication getPasswordAuthentication()
{  return new PasswordAuthentication(m_username,m_userpass);
}
}
//***********************
sendMailSession = Session.getInstance(props, new MyAuthenticator(username,password));

解决方案 »

  1.   

    import javax.mail.Authenticator;
    import javax.mail.PasswordAuthentication;public class MyAuthenticator extends Authenticator 
    {
       private String m_username = null;
       private String m_userpass = null;
       public void setUsername(String username) 
       {
          m_username = username;
       }
       public void setUserpass(String userpass) 
       {
          m_userpass = userpass;
       }
       public MyAuthenticator (String username, String userpass) 
       {
          super();
          setUsername(username);
          setUserpass(userpass);
       }
       public PasswordAuthentication getPasswordAuthentication() 
       {
          return new PasswordAuthentication(m_username, m_userpass);
       }
    }
    import javax.mail.*;
    import javax.activation.*;
    import java.util.*;
    import javax.mail.internet.*;public class SendMail 
    {
       public static void main(String[] args) 
       {
          try 
          {
             Properties props = new Properties();
             Session sendMailSession;
             Store store;
             Transport transport;
             props.put("mail.smtp.host", "smtp.163.com");
             
             props.put("mail.smtp.user", "jb_china2004");
             props.put("mail.smtp.password", "jbChina2004");
             //props.put("mail.smtp.auth","true");
             //sendMailSession = Session.getInstance(props, null);
             sendMailSession = Session.getInstance(props, new MyAuthenticator("jb_china2004","jbChina2004"));
             Message newMessage = new MimeMessage(sendMailSession);
             newMessage.setFrom(new InternetAddress("[email protected]"));
             newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
             newMessage.setSubject("测试发信");
             newMessage.setSentDate(new Date());
             newMessage.setText("测试发信成功,欢喜之中");
             transport = sendMailSession.getTransport("smtp");
             transport.send(newMessage);
             System.out.println ("发送成功");
          }
          catch(Exception e) 
          {
             e.printStackTrace();
          }
       }
    }还是不好用,
    提示
    javax.mail.MessagingException:553 you are not authorized to send mail as<mail from <[email protected]>>,authentication is required密码也告诉你啦, 麻烦你帮忙看一下呸,我没做过邮件发送, 都好几天没弄出来啦!
      

  2.   

    import javax.mail.*;
    import javax.activation.*;
    import java.util.*;
    import javax.mail.internet.*;public class SendMail 
    {
       public static void main(String[] args) 
       {
          try 
          {
             Properties props = new Properties();
             Session sendMailSession;
             Store store;
             Transport transport;
             SmtpAuthenticator sa=new SmtpAuthenticator("jb_china2004","jbChina2004"); 
             props.put("mail.smtp.host", "smtp.163.com");
             props.put("mail.smtp.port", "25");
             props.put("mail.smtp.auth","true");
    //         props.put("mail.smtp.user", "jb_china2004");
    //         props.put("mail.smtp.password", "jbChina2004");
    //         sendMailSession = Session.getInstance(props, null);
             sendMailSession = Session.getInstance(props, sa);
             Message newMessage = new MimeMessage(sendMailSession);
             newMessage.setFrom(new InternetAddress("[email protected]"));
             newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
             newMessage.setSubject("测试发信");
             newMessage.setSentDate(new Date());
             newMessage.setText("测试发信成功,欢喜之中");
             transport = sendMailSession.getTransport("smtp");
             transport.send(newMessage);
             System.out.println ("发送成功");
          }
          catch(Exception e) 
          {
             e.printStackTrace();
          }
       }
    }
     class SmtpAuthenticator extends Authenticator
    {    String username;
        String password;    public SmtpAuthenticator(String s, String s1)
        {
            username = s;
            password = s1;
        }    protected PasswordAuthentication getPasswordAuthentication()
        {
            return new PasswordAuthentication(username, password);
        }
    }
      

  3.   

    虽然已经结贴了,我还是要来拜一下chinajava