javax.activation.UnsupportedDataTypeException:无对象DCH for MIME类型multipart / mixed;边界 [英] javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary
本文介绍了javax.activation.UnsupportedDataTypeException:无对象DCH for MIME类型multipart / mixed;边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到的错误是,
javax.mail.MessagingException:IOException同时发送消息;
嵌套异常是:
javax.activation.UnsupportedDataTypeException:没有对象DCH for MIME类型multipart / mixed; border =---- = _ Part_0_145238.1392728439484
我寻找在stackoverflow中给出的解决方案帮助,但没有一个有帮助。
感谢提前
public void fileCreated(int wd,String rootPath,String name){
print(created+ rootPath +:+ name);
if(name.contains(。apk))
SendEmail(name);
else
System.out.println(不是APK文件);
}
void SendEmail(String strname){
String Path =D:/ POC / Email / apk folder /+ strname;
System.out.println(Path->+ Path);
属性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(属性已正确设置);
会话session = Session.getDefaultInstance(props,
new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication(){
返回新的PasswordAuthentication(SenderEmailID @ gmail.com,senderPassword);
}
}
);
System.out.println(会话创建成功);
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(这是使用JAVA MAIL 1.4.5发送的消息内容);
Multipart mulpart = new MimeMultipart();
mulpart.addBodyPart(msgbody);
// Attachement从这里开始。
msgbody = new MimeBodyPart();
javax.activation.DataSource source = new FileDataSource(Path);
msgbody.setDataHandler(new DataHandler(source));
msgbody.setFileName(strname);
message.setContent(mulpart);
System.out.println(附加邮件开始运送邮件);
//如果我发送电子邮件之前已经发送但没有附件的代码。
//Thread.currentThread()。setContextClassLoader(getClass()。getClassLoader());
Transport.send(message);
System.out.println(Mail sent successfully);
}
catch(MessagingException msg){
msg.printStackTrace();
}
catch(异常e){
e.printStackTrace();
}
}
解决方案
问题可以通过以下两个步骤获得解决方案。
- 确保java邮件是1.4.7(Previosly我用了1.4。 5导致了所有的混乱)。从 http://www.oracle.com/technetwork/java/index-138643.html下载a>
- 发送消息之前添加这段代码
Thread.currentThread()。setContextClassLoader(getClass()。getClassLoader());
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.
The Error I'm getting is,
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"
I looked for the solutions given in the stackoverflow for help but none of them where helpful.
Thanks in Advance
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.
- Make sure java mail is 1.4.7.(Previosly I used 1.4.5 which led to all confusions). Download it from http://www.oracle.com/technetwork/java/index-138643.html
- Add this piece of code before sending the message, Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
这篇关于javax.activation.UnsupportedDataTypeException:无对象DCH for MIME类型multipart / mixed;边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文