简体   繁体   中英

sending multiPart mail through yahoo mail cause javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;

It have been long since I asked for help on the forums but latly I have been Struggling with this problem for a couple of days.

read all the forums did all ppl did but no change.

here is my code

What the HI am doing wrong ?

by the way I am using javamail 5.1 and java 8 and already send text msg so no problem with properties

// Get system properties
    Properties properties = System.getProperties();
    // Setup mail server
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.host", mailHost);
    properties.put("mail.smtp.user", mailUserName);
    properties.put("mail.smtp.password", mailPassword);
    properties.put("mail.smtp.port", "587");
    properties.put("mail.smtp.auth", "true");

    // Get the default Session object.
    Session session = Session.getDefaultInstance(properties);

    try{
        // Create a default MimeMessage object.
        MimeMessage message = new MimeMessage(session);

        // Set From: header field of the header.
        message.setFrom(new InternetAddress(mD.mailUserName));

        // Set To: header field of the header.
        message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));

        Multipart multiPart = new MimeMultipart();
        MimeBodyPart textPart = new MimeBodyPart();
        textPart.setText("This is actual message", "text/html; charset=utf-8");

        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setContent(html, "text/html; charset=utf-8");
        multiPart.addBodyPart(textPart);
        multiPart.addBodyPart(htmlPart);
        message.setContent(multiPart);

        // Send message
        Transport transport = session.getTransport("smtp");
        transport.connect( mD.mailHost,mD.mailUserName,mD.mailPassword);

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader( javax.mail.Session.class.getClassLoader() );
        try
        {
            message.setContent(multiPart);
            //transport.sendMessage(message, message.getAllRecipients());
            Transport.send(message, message.getAllRecipients());
        }
        catch (MessagingException e)
        {
            e.printStackTrace();
        }
        finally
        {
            Thread.currentThread().setContextClassLoader(classLoader);
        }
        transport.close();
    }
    catch (MessagingException mex)
    {
        mex.printStackTrace();
    }

Your code has several of these common mistakes . Start by fixing them.

But your problem is most likely due to some sort of class loader problem. Tell us more about the environment in which your program is running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM