这个是我的测试类
package mail.send.test;import javax.mail.*;
import java.util.*;
import javax.mail.internet.*;public class SenderWithSMTPVe {
String host = "";
String user = "";
String password = "";
public void setHost(String host) {
this.host = host;
}
public void setAccount(String user, String password) {
this.user = user;
this.password = password;
}
public void send(String from, String to, String subject, String content) {
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
try {
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);
Message message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
to));
message.setSubject(subject);
message.setText(content);
message.saveChanges();
Transport transport = null;
transport = mailSession.getTransport("smtp");
if (transport == null) {
System.out.println("999999");
}
// Transport transport = mailSession.getTransport("smtp");
System.out.println("111");
System.out.println(host);
System.out.println(user);
System.out.println(password);
transport.connect(host, user, password);
System.out.println("222");
transport.sendMessage(message, message.getAllRecipients());
System.out.println("333");
transport.close();
} catch (Exception e) {
System.out.println(e);
}
} public static void main(String args[]) {
SenderWithSMTPVe sm = new SenderWithSMTPVe();
sm.setHost("smtp.126.com");
sm.setAccount("huoyutu86", "huoyutu1986jd");
sm.send("[email protected]", "[email protected]", "biaoti", "neirong");
}
}下面是控制台中消息DEBUG: setDebug: JavaMail version 1.3.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
111
smtp.126.com
huoyutu86
huoyutu1986jd
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.126.com", port 25220 *********************************************************
DEBUG SMTP: connected to host "smtp.126.com", port: 25EHLO WIDOWSXP-C71155
250-mail
250-PIPELINING
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg "PLAIN"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 dXNlcm5hbWU6
aHVveXV0dTg2
334 UGFzc3dvcmQ6
aHVveXV0dTE5ODZqZA==
550 用户被锁定
javax.mail.AuthenticationFailedException请问各位大虾怎么解决,我初学JMAIL,这个例子是网上下的