邮件发送错误,高手帮忙看看,本人邮件菜鸟
错误:18:11:51,873 ERROR [STDERR]
com.sun.mail.smtp.SMTPSendFailedException: 553 Mail from must equal authorized user
MyAuthenticator authenticator = null;
Properties pro = new Properties();
pro.put("mail.smtp.host", "smtp.126.com");
pro.put("mail.smtp.port","25");
pro.put("mail.smtp.auth", "true");
authenticator = new MyAuthenticator("a5782@126.com",config
.getPass());
Session sendMailSession = Session
.getDefaultInstance(pro, authenticator);
sendMailSession.setDebug(true);
try {
Message mailMessage = new MimeMessage(sendMailSession);
Address from = new InternetAddress("a5782@126.com");
mailMessage.setFrom(from);
Address toAddrArray = new InternetAddress("q343@126.com);
mailMessage.setRecipient(Message.RecipientType.TO, toAddrArray);
mailMessage.setSubject("流水号详细");
mailMessage.setSentDate(new Date());
// MiniMultipart类是一个容器类,包含MimeBodyPart类型的对象
Multipart mainPart = new MimeMultipart();
// 创建一个包含HTML内容的MimeBodyPart
BodyPart mbp = new MimeBodyPart();
// 设置HTML内容
mbp.setContent("", "text/html; charset=utf-8");
mainPart.addBodyPart(mbp);
mbp = new MimeBodyPart();
FileDataSource fds = new FileDataSource(path);// 得到数据源
mbp.setDataHandler(new DataHandler(fds));// 得到附件本身并至入BodyPart
mbp.setFileName(fds.getName());// 得到文件名同样至入BodyPart
mainPart.addBodyPart(mbp);
// 将MiniMultipart对象设置为邮件内容
mailMessage.setContent(mainPart);
// 发送邮件
Transport.send(mailMessage);
} catch (
MessagingException ex) {
ex.printStackTrace();
}
------解决方案--------------------
authenticator = new MyAuthenticator("a5782@126.com",config
.getPass());
这个位置authenticator = new MyAuthenticator("a5782",config
.getPass());
不需要写@126.com。