javamail发送非txt格式的附件时报错
主要代码是这样的:
MimeMessage sendMess = new MimeMessage(session);
BodyPart messageBodyParthtmltext = new MimeBodyPart();
BodyPart messageBodyattach = new MimeBodyPart();
String contentMessage=content;
String filename=fileAttachment;
try {
messageBodyParthtmltext.setContent(content,"text/html;charset=gb2312"); //html文本
MimeMultipart multipart = new MimeMultipart();
//multipart.setSubType("related");
multipart.addBodyPart(messageBodyParthtmltext);
//处理附件
FileDataSource source = new FileDataSource(filename);
messageBodyattach.setDataHandler(new DataHandler(source));
messageBodyattach.setFileName(filename);
multipart.addBodyPart(messageBodyattach);
sendMess.setSubject(subject,"GB2312");
sendMess.setFrom(new InternetAddress(sender));
sendMess.setRecipients(Message.RecipientType.TO, receiveAddress);
sendMess.setContent(multipart);
sendMess.saveChanges();
Transport.send(sendMess);
问题:附件是txt格式的可以发送出去,但发送jpg格式的时候就会报错了,我看了邮件信息已经生成了,就是发送的时候报错了
生成的邮件信息:
MIME-Version: 1.0
Content-Type: multipart/related;
boundary="----=_Part_9_21121948.1335595168741"
------=_Part_9_21121948.1335595168741
Content-Type: text/html;charset=gb2312
Content-Transfer-Encoding: 7bit
<img border="0" alt="" src="http://localhost:8080/MailStudy/kindeditor-v4.0.6/plugins/emoticons/images/13.gif" />
------=_Part_9_21121948.1335595168741
Content-Type: image/gif; name="D:\1.gif"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="D:\1.gif"
这里是一堆图片的编码,就不写了
------=_Part_9_21121948.1335595168741--
.(这是邮件结束标记)
报的错误是:DEBUG SMTP: got response code 451, with response: 451 4.0.0 Error processing message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只知道txt是ascii,非txt基本上都是二进制