0
回答
javamail发送非txt格式的附件时报错
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   
主要代码是这样的:   
  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.
<无标签>
举报
optmus
发帖于6年前 0回/157阅
顶部