我使用以下代码,代码执行到message.setSubject(body1);然后它不会抛出任何异常但直接停止执行完整的程序。与messageBodyPart.setText相同("嗨,状态邮件");当我尝试使用setSubject注释掉时。至少它甚至不会抛出异常。可能是什么问题?
String body1 = "TODAYS UPDATED FILES LIST";
Properties props = new Properties();
props.put("mail.smtp.auth", "false");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", Global.HOST);
props.put("mail.smtp.port", Global.PORT);
Session session = Session.getInstance(props);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(EMAIL_FROM));
for(int i=0;i<EMAIL_TO.size();i++){
message.addRecipient(Message.RecipientType.TO, new InternetAddress(EMAIL_TO.get(i)));
}
message.setSubject(body1);
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("Hi, Status mail");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(ATTATCHMENT_FILE_PATH);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(Global.ATTATCHMENT_FILE_NAME);
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport transport = session.getTransport("smtp");
transport.connect();
Transport.send(message);
System.out.println("Sent Mail Successfully");