drewr / postal

Clojure email support
MIT License
587 stars 85 forks source link

SMTP metadata problems #22

Open carlhoerberg opened 12 years ago

carlhoerberg commented 12 years ago

I have problems to configure Postal for smtp. It seems like the metadata is stripped of.

(postal/send-message #^{:host "email-smtp.us-east-1.amazonaws.com"
                      :user (get (System/getenv) "AWS_SMTP_USER")
                      :pass (get (System/getenv) "AWS_SMTP_PASSWORD")
                      :ssl true }
                   {:from 'validated@exampled.com' :to 'me@example.com' :subject 'test' :body 'test'})

Ignores the smtp settings and uses sendmail instead..

carlhoerberg commented 12 years ago

when i removed "#^" it worked.. why is that? should the documentation be updated?

drewr commented 12 years ago

Yes, that is a documentation bug. Clojure previously used #^{} for metadata.

carlhoerberg commented 12 years ago

nope still doesn't cut it, only a clean map is what works for me..

(i thought it worked in development previously, but it used sendmail, which actually worked on my machine..)

carlhoerberg commented 12 years ago

i've tested with both Clojure 1.3 and 1.4. Postal version 1.7.1

drewr commented 12 years ago

Ugh! You're right. This is due to a contribution that I didn't vet too well, and reveals a lack of test coverage. Let me work on fixing.

drewr commented 12 years ago

After looking at it further and trying it myself, there doesn't seem to be an issue there. Can you give me a failing test case?

carlhoerberg commented 12 years ago

In following code does only send-message3 throw javax.mail.AuthenticationFailedException, although all of them should've.

(ns postal-bug.core
  (:require [postal.core :as postal]))

(defn send-message [message]
  (postal/send-message ^{:host "email-smtp.us-east-1.amazonaws.com"
                         :ssl true }
                       message))

(def smtp-settings
  {:host "email-smtp.us-east-1.amazonaws.com"
   :ssl true })

(defn send-message2 []
  (postal/send-message ^smtp-settings
                       {:from "foo@example.com"
                        :to "bar@example.com"
                        :subject "foo"
                        :body "bar"}))

(defn send-message3 []
  (postal/send-message ^{:host "email-smtp.us-east-1.amazonaws.com"
                         :ssl true }
                       {:to "foo@example.com" 
                        :from "bar@example.com"
                        :subject "foo"
                        :body "bar"}))

(defn -main [& args]
  (send-message {:from "foo@example.com"
                 :to "bar@example.com"
                 :subject "foo"
                 :body "bar"})
  (send-message2)
  (send-message3))
carlhoerberg commented 12 years ago

oh! now i get it, the meta data is "attached" to the message, not to the function call..

carlhoerberg commented 12 years ago

but it's pretty uncommon to use different smtp settings per message within the same application, don't you think?

maybe an example with a "global" smtp-settings var in the README would be appropriate? would've at least helped a newbie like me :P

drewr commented 12 years ago

Sorry! Didn't know there was a misunderstanding of the meta usage. :-)

It may not be common, but as a library it shouldn't dictate what people do. Perhaps you have a policy where you need to send out a batch of messages in a stream but for billing reasons they each need to go through a different provider. The server info is ancillary to the content of the message, so meta seems like a logical place. If you'd rather use the two-arity version, go right ahead!

Thanks for using postal!