求javamail高手 AuthenticationFailedException

dennis0705 2010-05-30 10:07:00
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.sina.com.cn", port 25, isSSL false
220 irxd5-203.sinamail.sina.com.cn ESMTP
DEBUG SMTP: connected to host "smtp.sina.com.cn", port: 25

EHLO 20100316-0506
250-irxd5-203.sinamail.sina.com.cn
250-8BITMIME
250-SIZE 83886080
250-AUTH PLAIN LOGIN
250 AUTH=PLAIN LOGIN
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "83886080"
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "AUTH=PLAIN", arg "LOGIN"
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
ZGVubmlzMDgwMUBzaW5hLmNvbQ==
334 UGFzc3dvcmQ6
YWJjMTIzYWJjbA==
535 #5.7.0 Authentication failed
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at cn.itcast.mail.EmailSender.send(EmailSender.java:97)
at cn.itcast.mail.EmailSender.main(EmailSender.java:26)
...全文
369 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
izard999 2010-05-30
  • 打赏
  • 举报
回复
... 那可能就是 某些邮箱的问题了
dennis0705 2010-05-30
  • 打赏
  • 举报
回复
我换了个搜狐的,验证成功,谢谢
izard999 2010-05-30
  • 打赏
  • 举报
回复
AuthenticationFailedException
这里确实清清楚楚的认证失败嘛, 先看看再说.!
dennis0705 2010-05-30
  • 打赏
  • 举报
回复
应该不是用户名的问题吧,
这是我的java文件
public class EmailSender {
private static final String charset = "GBK";
private static final String defaultMimetype = "text/plain";

public static void main(String[] args) throws Exception {
EmailSender.send(new String[]{"165107433@qq.com"}, "邮件测试xx", "<b>洛卡网</b>",null , "text/html");
}
/**
* 发送邮件
* @param receiver 收件人
* @param subject 标题
* @param mailContent 邮件内容
* @param mimetype 内容类型 默认为text/plain,如果要发送HTML内容,应设置为text/html
*/
public static void send(String receiver, String subject, String mailContent, String mimetype) {
send(new String[]{receiver}, subject, mailContent, mimetype);
}
/**
* 发送邮件
* @param receivers 收件人
* @param subject 标题
* @param mailContent 邮件内容
* @param mimetype 内容类型 默认为text/plain,如果要发送HTML内容,应设置为text/html
*/
public static void send(String[] receivers, String subject, String mailContent, String mimetype) {
send(receivers, subject, mailContent, null, mimetype);
}
/**
* 发送邮件
* @param receivers 收件人
* @param subject 标题
* @param mailContent 邮件内容
* @param attachements 附件
* @param mimetype 内容类型 默认为text/plain,如果要发送HTML内容,应设置为text/html
*/
public static void send(String[] receivers, String subject, String mailContent, File[] attachements, String mimetype) {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.sina.com.cn");//smtp服务器地址
props.put("mail.smtp.auth", "true");//需要校验
Session session = Session.getDefaultInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("dennis@sina.com","123456");//登录用户名/密码 这里就不透露我和密码了
}
});
session.setDebug(true);
try {
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress("dennis@sina.com"));//发件人邮件

InternetAddress[] toAddress = new InternetAddress[receivers.length];
for (int i=0; i<receivers.length; i++) {
toAddress[i] = new InternetAddress(receivers[i]);
}
mimeMessage.setRecipients(Message.RecipientType.TO, toAddress);//收件人邮件
mimeMessage.setSubject(subject, charset);

Multipart multipart = new MimeMultipart();
//正文
MimeBodyPart body = new MimeBodyPart();
// body.setText(message, charset);不支持html
body.setContent(mailContent, (mimetype!=null && !"".equals(mimetype) ? mimetype : defaultMimetype)+ ";charset="+ charset);
multipart.addBodyPart(body);//发件内容
//附件
if(attachements!=null){
for (File attachement : attachements) {
MimeBodyPart attache = new MimeBodyPart();
//ByteArrayDataSource bads = new ByteArrayDataSource(byte[],"application/x-any");
attache.setDataHandler(new DataHandler(new FileDataSource(attachement)));
String fileName = getLastName(attachement.getName());
attache.setFileName(MimeUtility.encodeText(fileName, charset, null));
multipart.addBodyPart(attache);
}
}
mimeMessage.setContent(multipart);
// SimpleDateFormat formcat = new SimpleDateFormat("yyyy-MM-dd");
mimeMessage.setSentDate(new Date());//formcat.parse("2010-5-23")
Transport.send(mimeMessage);
} catch (Exception e) {
e.printStackTrace();
}
}

private static String getLastName(String fileName) {
int pos = fileName.lastIndexOf("\\");
if (pos > -1) {
fileName = fileName.substring(pos + 1);
}
pos = fileName.lastIndexOf("/");
if (pos > -1) {
fileName = fileName.substring(pos + 1);
}
return fileName;
}
}
izard999 2010-05-30
  • 打赏
  • 举报
回复
AuthenticationFailedException
认证失败.. 用户名密码是否正确了.?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧