1

I am trying to send email from Pedestal application hosted on Heroku using Postal. Email should be send in POST /send_email handler.

But it fails with:

clojure.lang.ExceptionInfo:
Interceptor Exception: No implementation of method: :make-input-stream of   
protocol: #'clojure.java.io/IOFactory found for class: nil

It works locally or via repl running on heroku.

Source:

(ns team-happiness.routes
  (:require [io.pedestal.http :as bootstrap]
            [io.pedestal.http.route.definition :refer [defroutes]]
            [io.pedestal.http.body-params :as body-params]
            [postal.core :as postal]))

(defn smtp []
  {:host (System/getenv "SENDGRID_HOST")
   :ssl true
   :user (System/getenv "SENDGRID_USERNAME")
   :pass (System/getenv "SENDGRID_PASSWORD")})

(defn mail []
  {:from "bla@bla.com"
   :to "bla@bla.com"
   :subject "Hi!"
   :body "Hello from Heroku!"})

(defn send-email [request]
  (postal/send-message (smtp) (mail))
  {:status 200 :headers {} :body ""})

(defroutes routes
  [[
    [ "/send_email" {:post send-email}]
  ]])

Stack trace:

2015-08-26T21:22:25.474347+00:00 app[web.1]: clojure.lang.ExceptionInfo: Interceptor Exception: No implementation of method: :make-input-stream of protocol: #'clojure.java.io/IOFactory found for class: nil
2015-08-26T21:22:25.474349+00:00 app[web.1]:    at clojure.core$ex_info.invoke(core.clj:4593) ~[na:na]
2015-08-26T21:22:25.474350+00:00 app[web.1]:    at io.pedestal.impl.interceptor$throwable__GT_ex_info.invoke(interceptor.clj:31) ~[na:na]
2015-08-26T21:22:25.474352+00:00 app[web.1]:    at io.pedestal.impl.interceptor$try_f.invoke(interceptor.clj:53) ~[na:na]
2015-08-26T21:22:25.474354+00:00 app[web.1]:    at io.pedestal.impl.interceptor$enter_all_with_binding.invoke(interceptor.clj:141) ~[na:na]
2015-08-26T21:22:25.474355+00:00 app[web.1]:    at io.pedestal.impl.interceptor$enter_all$fn__12957.invoke(interceptor.clj:156) ~[na:na]
2015-08-26T21:22:25.474357+00:00 app[web.1]:    at clojure.lang.AFn.applyToHelper(AFn.java:152) ~[team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474358+00:00 app[web.1]:    at clojure.lang.AFn.applyTo(AFn.java:144) ~[team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474359+00:00 app[web.1]:    at clojure.core$apply.invoke(core.clj:630) ~[na:na]
2015-08-26T21:22:25.474361+00:00 app[web.1]:    at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1868) ~[na:na]
2015-08-26T21:22:25.474362+00:00 app[web.1]:    at clojure.lang.RestFn.invoke(RestFn.java:425) ~[team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474364+00:00 app[web.1]:    at io.pedestal.impl.interceptor$enter_all.invoke(interceptor.clj:154) ~[na:na]
2015-08-26T21:22:25.474365+00:00 app[web.1]:    at io.pedestal.impl.interceptor$execute.invoke(interceptor.clj:272) [na:na]
2015-08-26T21:22:25.474367+00:00 app[web.1]:    at io.pedestal.http.impl.servlet_interceptor$interceptor_service_fn$fn__15523.invoke(servlet_interceptor.clj:398) [na:na]
2015-08-26T21:22:25.474368+00:00 app[web.1]:    at io.pedestal.http.servlet.FnServlet.service(servlet.clj:28) [na:na]
2015-08-26T21:22:25.474369+00:00 app[web.1]:    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:751) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474371+00:00 app[web.1]:    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:566) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474372+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1111) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474373+00:00 app[web.1]:    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:498) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474375+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1045) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474376+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474377+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:98) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474379+00:00 app[web.1]:    at org.eclipse.jetty.server.Server.handle(Server.java:461) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474380+00:00 app[web.1]:    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474381+00:00 app[web.1]:    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474394+00:00 app[web.1]:    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:534) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474395+00:00 app[web.1]:    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474397+00:00 app[web.1]:    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536) [team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474398+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
2015-08-26T21:22:25.474400+00:00 app[web.1]: Caused by: java.lang.IllegalArgumentException: No implementation of method: :make-input-stream of protocol: #'clojure.java.io/IOFactory found for class: nil
2015-08-26T21:22:25.474401+00:00 app[web.1]:    at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:554) ~[na:na]
2015-08-26T21:22:25.474402+00:00 app[web.1]:    at clojure.java.io$eval3371$fn__3372$G__3360__3379.invoke(io.clj:69) ~[na:na]
2015-08-26T21:22:25.474403+00:00 app[web.1]:    at clojure.java.io$input_stream.doInvoke(io.clj:136) ~[na:na]
2015-08-26T21:22:25.474404+00:00 app[web.1]:    at clojure.lang.RestFn.invoke(RestFn.java:410) ~[team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474406+00:00 app[web.1]:    at postal.support$pom_version.invoke(support.clj:61) ~[na:na]
2015-08-26T21:22:25.474407+00:00 app[web.1]:    at postal.support$user_agent.invoke(support.clj:67) ~[na:na]
2015-08-26T21:22:25.474408+00:00 app[web.1]:    at postal.message$make_jmessage.invoke(message.clj:177) ~[na:na]
2015-08-26T21:22:25.474410+00:00 app[web.1]:    at postal.smtp$smtp_send_STAR_$fn__17638.invoke(smtp.clj:34) ~[na:na]
2015-08-26T21:22:25.474411+00:00 app[web.1]:    at clojure.core$map$fn__560.invoke(core.clj:2624) ~[na:na]
2015-08-26T21:22:25.474412+00:00 app[web.1]:    at clojure.lang.LazySeq.sval(LazySeq.java:40) ~[team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474414+00:00 app[web.1]:    at clojure.lang.LazySeq.seq(LazySeq.java:49) ~[team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474419+00:00 app[web.1]:    at clojure.lang.RT.seq(RT.java:507) ~[team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474420+00:00 app[web.1]:    at clojure.core$seq__27.invoke(core.clj:137) ~[na:na]
2015-08-26T21:22:25.474421+00:00 app[web.1]:    at postal.smtp$smtp_send_STAR_.invoke(smtp.clj:35) ~[na:na]
2015-08-26T21:22:25.474423+00:00 app[web.1]:    at postal.smtp$smtp_send.doInvoke(smtp.clj:58) ~[na:na]
2015-08-26T21:22:25.474424+00:00 app[web.1]:    at clojure.lang.RestFn.invoke(RestFn.java:423) ~[team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474425+00:00 app[web.1]:    at postal.core$send_message.invoke(core.clj:35) ~[na:na]
2015-08-26T21:22:25.474427+00:00 app[web.1]:    at team_happiness.routes$send_email.invoke(routes.clj:31) ~[team-happiness-0.0.1.jar:na]
2015-08-26T21:22:25.474428+00:00 app[web.1]:    at io.pedestal.interceptor$eval13068$fn__13069$fn__13070.invoke(interceptor.clj:38) ~[na:na]
2015-08-26T21:22:25.474429+00:00 app[web.1]:    at io.pedestal.impl.interceptor$try_f.invoke(interceptor.clj:50) ~[na:na]
2015-08-26T21:22:25.474431+00:00 app[web.1]:    ... 25 common frames omitted
2015-08-26T21:22:25.474631+00:00 app[web.1]: INFO  i.p.http.impl.servlet-interceptor - {:line 266, :msg "sending error", :message "Internal server error: exception"}
Kirill Salykin
  • 681
  • 6
  • 19
  • Are you using the https://github.com/upworthy/heroku-buildpack-boot buildpack? (that should be fine, just want to get it straight) – codefinger Aug 26 '15 at 20:31
  • yes, indeed. the only working one. – Kirill Salykin Aug 26 '15 at 20:35
  • What value are you using for `SENDGRID_HOST`? – codefinger Aug 26 '15 at 20:50
  • It is possible to send email but only using heroku run boot repl. – Kirill Salykin Aug 26 '15 at 20:59
  • Please post a stack trace as well as the minimal code necessary to reproduce the problem (or at least the code from your project which is responsible for sending the email). – Nathan Davis Aug 26 '15 at 21:12
  • Please find link to public Github repository. Stack trace added. – Kirill Salykin Aug 26 '15 at 21:25
  • I did notice that the default port for ssl with postal is 465, but SendGrid says they use 587. When I set this port in the smtp function, I got a `javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?` exception. – codefinger Aug 26 '15 at 21:33
  • According to https://sendgrid.com/docs/Classroom/Basics/smtp_ports.html 465 port is also available. – Kirill Salykin Aug 26 '15 at 21:35
  • I think this may be a bug postal, in which it can't read this file from the uberjar https://github.com/drewr/postal/blob/master/src/postal/support.clj#L61 That would explain why it works from the repl maybe? – codefinger Aug 26 '15 at 21:39
  • indeed! i just was looking on this line https://github.com/drewr/postal/blob/master/src/postal/support.clj#L64 – Kirill Salykin Aug 26 '15 at 21:39
  • @codefinger can you recommend other project for sending mails? Not this https://github.com/clojurewerkz/mailer – Kirill Salykin Aug 26 '15 at 21:48
  • @codefinger it is the pom version reading issue. I workaround it with (System/setProperty "postal.version" "1") Can you make an answer from you comment? I'll mark it as accepted. Thank you! – Kirill Salykin Aug 26 '15 at 21:53
  • @sync, I see the links, but its best to put this information directly in the post. Source code repositories change and/or go away. If the source were pertinent to the solution, there would be no reliable way for future visitors to tell what that code was, unless it's in the post. – Nathan Davis Aug 27 '15 at 02:31
  • @NathanDavis - you are right, i'll add source and stack trace. Thank you. – Kirill Salykin Aug 27 '15 at 06:34

1 Answers1

2

I was able to get this working by setting the following config var:

$ heroku config:set JVM_OPTS="-Dpostal.version=1.11.3"

The problem, it seems, is that postal tries to determine the version of itself by inspecting a pom.properties file inside of it's jar. But because this is an uberjar, it's a jar inside of a jar, and the attempt to read the input stream fails.

By setting the above system property, it never looks in the jar.

codefinger
  • 10,088
  • 7
  • 39
  • 51
  • 1
    Not abandoned! Notifications just get buried in my email. This is very old code that needs to be reworked. Will take it up on the issue. – drewr Nov 05 '15 at 21:05
  • Fixed the notification problem with some more aggressive gmail filters. – drewr Nov 05 '15 at 21:07