|
DEBUG: setDebug: JavaMail version 1.3.1
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.163.com", port 25
220 163.com Anti-spam GT for Coremail System (163com[20050206])
DEBUG SMTP: connected to host "smtp.163.com", port: 25
EHLO nikodan
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
enh5b25nd2Vi
334 UGFzc3dvcmQ6
ODg4ODg4
550 用户被锁定
javax.mail.AuthenticationFailedException
-----------------------------------------
源代码:
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
-------------------------
public boolean sendEmail(String to,String subject,String content) {
String host="smtp.163.com";//mail.thinkrev.com
String user="zxyongweb";
String password="zxyongdb";
String from = "zxyongweb@163.com";
Properties props = new Properties();
props.put("mail.smtp.host", host);//指定SMTP服务器
props.put("mail.smtp.auth", "true");//指定是否需要SMTP验证
try
{
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);//是否在控制台显示debug信息
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 = mailSession.getTransport("smtp");
transport.connect(host, user, password);
log.error("开始发送:");
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}catch(Exception e)
{
log.error("发邮件失败:"+e);
System.out.println(e);
return false;
}
log.error("开始成功:");
return true;
} |
|