错误:18:11:51,873 ERROR [STDERR] com.sun.mail.smtp.SMTPSendFailedException: 553 Mail from must equal authorized userMyAuthenticator 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("[email protected]",config
.getPass());
Session sendMailSession = Session
.getDefaultInstance(pro, authenticator);
sendMailSession.setDebug(true);
try {
Message mailMessage = new MimeMessage(sendMailSession);
Address from = new InternetAddress("[email protected]");
mailMessage.setFrom(from); Address toAddrArray = new InternetAddress("[email protected]); 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();
}