这个问题通常是由发送的消息缺少内容造成的。确保正确设置消息的正文或附件。此外,您也可以尝试强制设置邮件会话的协议为SSL或TLS。以下是一个设置SMTP协议为TLS的JavaMail示例代码:
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
//compose message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("Hello");
message.setText("Hello World");
//send message
Transport.send(message);