MessagingExceptionIOException while sending message in java?

前端 未结 8 941
说谎
说谎 2021-01-19 02:41

I use the following code to send mail.Text message sending is working fine but Mail with attachment is not working it gives the Exception.How to solve this

相关标签:
8条回答
  • 2021-01-19 03:24

    This may stem from class loading issues (duplicat versions of activation.jar). See for example http://forum.springsource.org/archive/index.php/t-69180.html

    or google some more

    0 讨论(0)
  • 2021-01-19 03:30

    Firstly, you could make your code a little more concise by using MimeBodyPart.attachFile() instead of wrangling the DataSource/DataHandler code yourself.

    Secondly, try setting the Content-Type and Content-Disposition headers on your attachment part with appropriate values. (attachFile will set the Content-Disposition for you by default.) For instance,

    messageBodyPart = new MimeBodyPart();
    messageBodyPart.attachFile(new File("mail.txt"));
    messageBodyPart.setHeader("Content-Type", "text/plain; charset=\"us-ascii\"; name=\"mail.txt\"");
    



    EDIT:

    After thinking a bit, this has to be something amiss with class loading. Please check this other SO thread to see if it remedies your situation. (General issue: Probably an extra activation.jar in your classpath; a few other possibilities also thought to cause it.)

    0 讨论(0)
提交回复
热议问题