SendMail themail = new SendMail("smtp.263xmail.com");//发送邮件的服务器
 themail.setNeedAuth(true);
    //设置主题
themail.setSubject("Retrieve password");//设置邮件内容
themail.setBody("Your new password is:\n"+rndString+"\n Please change your password after you log in!");
//设置收件人Email地址
.setTo(accEmail);
    //设置发件人Eamil地址
themail.setFrom("[email protected]");
    //设置发件人Email的用户名和密码
themail.setNamePass("[email protected]", "zggykjigctoc");
    //判断是否有发送出去
  if (themail.sendout() == false) {
System.out.println("The email send failure!");
request.setAttribute("msg","The email send fails!");
    }else{
     //System.out.println("getBackUserPwd------------");
     AccService.updatePws(accPSW, accID);
     request.setAttribute("msg", "your password has already sent to your mail box");
    }

解决方案 »

  1.   

    Thanks!
    I had resolved this question!import javax.mail.*; 
    import javax.mail.internet.*; 
    import javax.activation.*; 
    import java.io.*; 
    import java.util.*; public class SendMail { 
    public SendMail() { 

    public static void main(String []args) 

    try 
    { Properties mailProps = new Properties(); 
    mailProps.put("mail.smtp.host","smtp.163.com");
    mailProps.put("mail.smtp.auth", "true");
    mailProps.put("username","qxwtt");
    mailProps.put("password","7405130");
    Session mailSession = Session.getInstance(mailProps, new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication()
    {
    return new PasswordAuthentication("qxwtt",
    "7405130");
    }
    });
     
    MimeMessage message = new MimeMessage(mailSession); 
    message.setFrom(new InternetAddress("[email protected]")); 
    message.setRecipient(Message.RecipientType.TO,new InternetAddress("[email protected]")); 
    message.setSubject("Mail Test"); 
    MimeMultipart multi = new MimeMultipart(); 
    BodyPart textBodyPart = new MimeBodyPart(); 
    textBodyPart.setText("Hello World!"); 
    multi.addBodyPart(textBodyPart); 
    message.setContent(multi); 
    message.saveChanges(); 
    Transport.send(message); 

    catch (Exception ex) 

    System.err.println("邮件发送失败的原因是:"+ex.getMessage()); 
    System.err.println("具体错误原因:"); 
    ex.printStackTrace(System.err);