java.io.IOException: Exception writing Multipart 发送邮件错误

 发送邮件时候出现如下错误,

javax.mail.MessagingException: IOException while sending message;
  nested exception is:
    java.io.IOException: Exception writing Multipart
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1365)
    at com.util.email.SendEmailUtil.sendOutEmail(SendEmailUtil.java:383)
    at com.ccb.thred.EmailMessageTask.retryTimes(EmailMessageTask.java:101)
    at com.ccb.thred.EmailMessageTask.run(EmailMessageTask.java:85)
    at com.util.thread.ThreadPool$WorkThread.run(ThreadPool.java:88)
Caused by: java.io.IOException: Exception writing Multipart
    at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:86)
    at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889)
    at javax.activation.DataHandler.writeTo(DataHandler.java:317)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1694)
    at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1913)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1315)
    ... 4 more
Caused by: javax.mail.MessagingException: Empty multipart: multipart/mixed; 
    boundary="----=_Part_0_1152361475.1600839705183"
    at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:556)
    at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:84)
    ... 9 more

 原因是邮件的内容为null(注意不是为""),如果不发送内容的话,可以把值设置为"",而不是为null,代码如下

if (null != email.getMailContent()){
    this.setBody(email.getMailContent());
}else {
    this.setBody("");
}

 

                                                                             --不积跬步,无以至千里;不积小流,无以成江海

你可能感兴趣的:(java)