javax.activation.UnsupportedDataTypeException: MIME 类型 multipart/mixed 没有对象 DCH;边界 [英] javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary
本文介绍了javax.activation.UnsupportedDataTypeException: MIME 类型 multipart/mixed 没有对象 DCH;边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我正在内联编写将侦听目录的代码.当该目录更新为 .apk 文件时,我会将带有此 .apk 文件的邮件发送到 gmail 帐户.我在我的程序中使用 Jnotify 和 JAVA Mail.
Currently I'm inline of writing a code that will be listening to a directory. when the directory is updated with .apk file, I'll send a mail with this .apk file to a gmail account. I'm using Jnotify and JAVA Mail in my program.
我得到的错误是,
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary="----=_Part_0_145238.1392728439484"
我寻找了 stackoverflow 中给出的解决方案以寻求帮助,但没有一个有帮助.
I looked for the solutions given in the stackoverflow for help but none of them where helpful.
提前致谢
public void fileCreated(int wd, String rootPath, String name) {
print("created " + rootPath + " : " + name);
if (name.contains(".apk"))
SendEmail(name);
else
System.out.println("Not the APK file");
}
void SendEmail(String strname){
String Path = "D:/POC/Email/apk folder/"+strname;
System.out.println("Path->" + Path);
Properties props = new Properties();
props.put("mail.smtp.host","173.194.78.108");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth","true");
props.put("mail.smtp.port","465");
System.out.println("Properties has been set properly");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("SenderEmailID@gmail.com", "senderPassword");
}
}
);
System.out.println("Session Created successfully");
try{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("SenderEmailID@gmail.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("ToReceiverEmailID@gmail.com"));
message.setSubject("Android : " + strname);
MimeBodyPart msgbody = new MimeBodyPart();
msgbody.setText("This is the message content which is sent using JAVA MAIL 1.4.5");
Multipart mulpart = new MimeMultipart();
mulpart.addBodyPart(msgbody);
//Attachement Starts here.
msgbody = new MimeBodyPart();
javax.activation.DataSource source = new FileDataSource(Path);
msgbody.setDataHandler(new DataHandler(source));
msgbody.setFileName(strname);
message.setContent(mulpart);
System.out.println("Attached the message going to start transporting the mail");
//If I've the code before sending the email is getting sent but without attachment.
//Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
Transport.send(message);
System.out.println("Mail Sent successfully");
}
catch(MessagingException msg){
msg.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
}
推荐答案
这个问题可以通过以下两个步骤来解决.
This issue can get a solution by taking up the below two steps.
- 确保 java 邮件是 1.4.7.(以前我使用 1.4.5 这导致了所有的混乱).从 http://www.oracle.com/technetwork/java/index- 下载它138643.html
- 在发送消息之前添加这段代码:
Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
这篇关于javax.activation.UnsupportedDataTypeException: MIME 类型 multipart/mixed 没有对象 DCH;边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文