-
Notifications
You must be signed in to change notification settings - Fork 86
Return the reply from SMTP server when sending single message #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,15 +26,26 @@ | |
| [postal.support :only [make-props]]) | ||
| (:import [javax.mail Transport Session])) | ||
|
|
||
| (defn- send-single [transport ^javax.mail.Message jmsg] | ||
| (.sendMessage transport jmsg (.getAllRecipients jmsg)) | ||
| {:code (.getLastReturnCode transport) | ||
| :error :SUCCESS | ||
| :message (.getLastServerResponse transport)}) | ||
|
|
||
| (defn- send-multiple [transport jmsgs] | ||
| (doseq [^javax.mail.Message jmsg jmsgs] | ||
| (send-single transport jmsg)) | ||
| {:code 0 :error :SUCCESS :message "messages sent"}) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this single return value will mask all the return values from the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe sendMessage will throw an exception if any of the messages fail. For that reason, the API for sending multiple messages is problematic. (If something fails, it's hard for the caller to figure out which messages succeeded.) But it's fine for callers that don't care to track that anyway. I tried to not change the interface at all, since you might have users that depend on it. I'm not sure what policy you have for breaking changes. |
||
|
|
||
| (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 user pass) | ||
| (let [jmsgs (map #(make-jmessage % session) msgs)] | ||
| (doseq [^javax.mail.Message jmsg jmsgs] | ||
| (.sendMessage transport jmsg (.getAllRecipients jmsg))) | ||
| {:code 0 :error :SUCCESS :message "messages sent"}))) | ||
| (if (= (count msgs) 1) | ||
| (send-single transport (first jmsgs)) | ||
| (send-multiple transport jmsgs))))) | ||
|
|
||
| (defn smtp-send | ||
| ([msg] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note you removed all the newlines from these (or, likely your editor did).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Yes, I have configured emacs to remove trailng spaces. Sorry for not reviewing the commit more thoroughly.