dmurvihill/courier

Unable to send multipart messages.

Closed this issue · 12 comments

On Windows Machines I get the following error, when I try to send multipart messages.
This is a bug with 1.0.0 and 2.0.0 too.

javax.mail.MessagingException: IOException while sending message
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1365)
at javax.mail.Transport.send0(Transport.java:255)
at javax.mail.Transport.send(Transport.java:124)
at courier.Mailer.$anonfun$apply$1(mailer.scala:37)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:654)
at scala.util.Success.$anonfun$map$1(Try.scala:251)
at scala.util.Success.map(Try.scala:209)
at scala.concurrent.Future.$anonfun$map$1(Future.scala:288)
at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)
at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
boundary="----=_Part_0_1807859575.1582802492185"
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:896)
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1694)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1913)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1315)
... 16 common frames omitted

Thanks for the report, I will look into the issue tonight. ATM I don't have access to a Windows machine.

Hey @hajnalmt, I'll try to get access to a Windows machine today as well. Could you send a reproduction project when you get a chance?

I found the same error on our CI. But locally on my Windows it goes through.

Thanks for the report.

I've created a branch in my fork, with two examples: https://github.com/daddykotex/courier/tree/examples

Can you checkout that branch and run both examples and tell me if they work on your platform?

I was able to run both:

  • on macos
  • on windows 10 (in cmd)
  • on windows 10 (in an ubuntu 18 developer subsystem)

To run the examples, checkout the branch, set both environment variables SMTP_USERNAME and SMTP_PASSWORD and run sbt.

To run the simple example run:
examples/runMain courier.SimpleExample.

To run the multipart example, run:
examples/runMain courier.MultipartExample /path/to/your/image.jpg or on windows: examples/runMain courier.MultipartExample C:\Path\To\Your\Image.jpg

As I'm not able to reproduce, I'll put that on hold until we have more information. Relevant information would be:

  • core logic code surrounding the email construction (especially the type of file attached)
  • full windows version
  • java version

Also, please refer to this SO question as the problem may come from your class loader setup: https://stackoverflow.com/questions/21856211/javax-activation-unsupporteddatatypeexception-no-object-dch-for-mime-type-multi

Your library uses Future to send the mail in another task. I'm guessing there is no easly way to try out the fixes as suggested by SO.

Anyway, the issue is quite interesting. This problem only happens in one specific project of ours. We have a wrapper around Courier in a core project. We have 5-10 projects using Courier 2.0.0 with no issues so far.

My guess is that the OS, Windows in this case, needs support for the type of file that's attached. There must be support for some types of files: csv, jpg, pdf but maybe more complex files are not supported.

I'd like to know the type of attachment you and the @hajnalmt are trying to send to debug further more. Maybe this has nothing to do with the attachment either.

I myself actually don't try to send any attachments. It is a simple HTML mail. It works on Windows and Linux CI for all of your projects, but for 1 project it does not work on Linux CI.

I will try to fork your repo, release it under our Artifactory and patch based on SO suggestions.

It will be a lot easier for us to help if we can get a look at the non-working code.

Hello, thank you for the quick responses!
So I ran your examples, and they are working on my computers absolutely well. Even the attachment parts. The issue is coming for me by sending just a plain html multipart message.
It means that this isn't a windows related problem at all.

I tried the SO answers too, but I did not succeed solving this issue in that particular project.
It's quite annoying, now I will try to figure out what can be the difference between the 2 project setup. Right now I do not have a clue at all.

@zzvara Are you able to run the examples provided by @dmurvihill?

Tomorrow I will try to create a reproduction project somehow based on the one I have here.

Closing for inactivity.