Play mailer plugin 5.0.0 sporadic attachment error

56 views
Skip to first unread message

arun....@gmail.com

unread,
Jun 1, 2017, 4:51:46 PM6/1/17
to Play Framework

Below is the sporadic stack trace  for attaching a file. Now the file attachment fails randomly and some times the attachment goes through fine without issue. 
We are using CompletableFuture.runAsync(() -> {}) for publishing the emails using the injected mailer client. Any help is appreciated.


Build.sbt dependency
"com.typesafe.play" %% "play-mailer" % "5.0.0"



2017-05-31 18:28:18,344 [ERROR] from application in application-akka.actor.default-dispatcher-49034 - org.apache.commons.mail.EmailException: Sending the email to the following server failed : mailrelay.org.com:25
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        java.io.FileNotFoundException: /tmp/playtemp3112763383526680968/multipartBody9095873588579429689asTemporaryFile (No such file or directory)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1167)
        at javax.mail.Transport.send0(Transport.java:195)
        at javax.mail.Transport.send(Transport.java:124)
        at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411)
        ... 17 more
Caused by: java.io.FileNotFoundException: /tmp/playtemp3112763383526680968/multipartBody9095873588579429689asTemporaryFile (No such file or directory)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at javax.activation.FileDataSource.getInputStream(FileDataSource.java:97)
        at javax.activation.DataHandler.writeTo(DataHandler.java:305)
        at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485)
        at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:865)
        at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:462)
        at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103)
        at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889)
        at javax.activation.DataHandler.writeTo(DataHandler.java:317)
        at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485)
        at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1773)
        at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1119)
        ... 20 more 

arun....@gmail.com

unread,
Jun 3, 2017, 12:11:44 PM6/3/17
to Play Framework
Can someone please point to what might be causing this issue. We are observing this more often in our production system. 

Will Sargent

unread,
Jun 4, 2017, 3:26:24 AM6/4/17
to play-fr...@googlegroups.com
You're accessing a temporary file that was uploaded to Play: see 

/tmp/playtemp3112763383526680968/multipartBody9095873588579429689asTemporaryFile (No such file or directory)

Those files are deliberately transient and are deleted after completion, so they only exist in the completion scope.  You should use moveTo to move the file somewhere else that will not be deleted:

def upload = Action(parse.multipartFormData) { request =>
  request.body.file("picture").map { picture =>
    import java.io.File
    val filename = picture.filename
    val contentType = picture.contentType
    picture.ref.moveTo(new File(s"/tmp/picture/$filename"))
    Ok("File uploaded")
  }.getOrElse {
    Redirect(routes.Application.index).flashing(
      "error" -> "Missing file")
  }
}


--
Will Sargent
Engineer, Lightbend, Inc.


--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/4b9ae22a-5874-460e-93cb-19cffbd49262%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

arun....@gmail.com

unread,
Jun 16, 2017, 4:07:21 PM6/16/17
to Play Framework
Perfect. That fixed my situation by renaming the temp file to persist to disk and later publish the e-mail.
Can you please update the Java documentation for file upload in 2.5 doc by specifying the renaming aspect. I personally used renameTo method from Java 7 File API : https://docs.oracle.com/javase/7/docs/api/java/io/File.html

To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages