Permalink
Browse files

Don't coerce user/pass to String.

JavaMail turns on authentication in the `connect()` arity when
user/pass are not null.  This isn't compatible with some SMTP servers,
and it's a bug anyway for postal to coerce nil to a string here.
Closes #31.
  • Loading branch information...
1 parent 5e1d33c commit c9ca3ae08d7ff1c07a50d04cf2b23b649708d723 @drewr committed May 15, 2013
Showing with 16 additions and 9 deletions.
  1. +10 −9 src/postal/smtp.clj
  2. +6 −0 test/postal/test/smtp.clj
View
19 src/postal/smtp.clj
@@ -28,8 +28,9 @@
(defn ^:dynamic smtp-send* [^Session session ^String proto
{:keys [host port user pass]} msgs]
+ (assert (or (and (nil? user) (nil? pass)) (and user pass)))
(with-open [transport (.getTransport session proto)]
- (.connect transport host port (str user) (str pass))
+ (.connect transport host port user pass)
(let [jmsgs (map #(make-jmessage % session) msgs)]
(doseq [^javax.mail.Message jmsg jmsgs]
(.sendMessage transport jmsg (.getAllRecipients jmsg)))
@@ -46,12 +47,12 @@
([args & msgs]
(let [{:keys [host port user pass sender ssl]
:or {host "localhost"}} args
- port (if (nil? port)
- (if ssl 465 25)
- port)
- proto (if ssl "smtps" "smtp")
- args (merge args {:port port
- :proto proto})
- session (doto (Session/getInstance (make-props sender args))
- (.setDebug false))]
+ port (if (nil? port)
+ (if ssl 465 25)
+ port)
+ proto (if ssl "smtps" "smtp")
+ args (merge args {:port port
+ :proto proto})
+ session (doto (Session/getInstance (make-props sender args))
+ (.setDebug false))]
(smtp-send* session proto args msgs))))
View
6 test/postal/test/smtp.clj
@@ -59,4 +59,10 @@
{"mail.smtp.user" "foo"
"mail.smtp.port" 465
"mail.smtp.auth" "true"
+ "mail.smtp.host" "smtp.bar.dom"})
+ (is-props {:host "smtp.bar.dom"
+ :user nil
+ :pass nil}
+ {"mail.smtp.port" 25
+ "mail.smtp.auth" "false"
"mail.smtp.host" "smtp.bar.dom"}))

0 comments on commit c9ca3ae

Please sign in to comment.