Failed messages: javax.mail.internet.ParseException: Expected ‘/’, got null
····这是通过邮件附件形式发送文件时遇到的错误信息。
····出现问题的原因是addAttachment方法中的第三个参数contentType设置的有问题
public void addAttachment( String attachmentFilename, InputStreamSource inputStreamSource, String contentType)
····比如我是这样设置的:messageHelper.addAttachment(subject,dataSource,"xls");
····我是想通过附件的形式发送excel文件,结果这样设置报上面的错误了,应该是有要求的格式设置,很抱歉,找了半天没找到标准格式的写法,但是发现了一个其他的方法,可以解决这个问题:
DataSource dataSource = new ByteArrayDataSource(byteArray, "application/excel");
messageHelper.addAttachment(subject,dataSource);
····其中byteArray是byte[]格式的,也就是你想通过附件发送的字节内容,先通过DataSource包装一下,同时在包·装过程中设置好 "application/excel"的excel格式,亲测问题可解。
····相信遇到这个问题时大家已经是有大体思路了,所以写的很粗略,网上也有很多excel附件上传的帖子,把这个错误摘出来,仅是想提示一下大家。