编写qq邮箱时报错,求dalao帮忙看看
错误:
DEBUG: setDebug: JavaMail version 1.6.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.exmail.qq.com", port 25, isSSL false
220 smtp.qq.com Esmtp QQ Mail Server
DEBUG SMTP: connected to host "smtp.exmail.qq.com", port: 25
EHLO 192.168.43.238
250-smtp.qq.com
250-PIPELINING
250-SIZE 73400320
250-STARTTLS
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN
250-MAILCOMPRESS
250 8BITMIME
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "73400320"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "MAILCOMPRESS", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: protocolConnect login, host=smtp.exmail.qq.com, user=xxxxxxx@qq.com, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN failed
Exception in thread "main" javax.mail.AuthenticationFailedException: 535 Error: ÇëʹÓÃÊÚȨÂëµÇ¼¡£ÏêÇéÇë¿´: http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:965)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:876)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:780)
at javax.mail.Service.connect(Service.java:366)
at javax.mail.Service.connect(Service.java:246)
at javax.mail.Service.connect(Service.java:267)
at org.java.demo.Demo.main(Demo.java:53)
源码:
public static void main(String[] args) throws AddressException, MessagingException {
// TODO Auto-generated method stub
String from = "xxxxxxx@qq.com";
String to = "xxxxxxxx@qq.com";
String subject = "test";
String body = "test!!!";
String smtpHost = "smtp.exmail.qq.com";
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp"); // 使用的协议(JavaMail规范要求)
props.setProperty("mail.smtp.host", smtpHost); // 发件人的邮箱的 SMTP服务器地址
props.setProperty("mail.smtp.auth", "true"); // 请求认证,参数名称与具体实现有关
// 创建Session实例对象
Session session = Session.getDefaultInstance(props);
// 创建MimeMessage实例对象
MimeMessage message =new MimeMessage(session);
// 设置发件人
message.setFrom(new InternetAddress(from));
// 设置收件人
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
// 设置发送日期
message.setSentDate(new Date());
// 设置邮件主题
message.setSubject(subject);
// 设置纯文本内容的邮件正文
message.setText(body);
// 保存并生成最终的邮件内容
message.saveChanges();
// 设置为debug模式, 可以查看详细的发送 log
session.setDebug(true);
// 获取Transport对象
Transport transport = session.getTransport("smtp");
// 填写QQ邮箱的SMTP的授权码
transport.connect(from, "cmrtxucxglgvdigb");
// 发送,message.getAllRecipients()
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
注:smtp已开启,授权码也是正确