Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ To use SMTP, add an argument map before the message with at least
:to "foo@example.com"
:subject "Hi!"
:body "Test."})
{:code 0, :error :SUCCESS, :message "message sent"}
{:code 250, :error :SUCCESS, :message "250 Ok\n"}
postal.core>

For legacy compatibility, you can also supply these connection
Expand All @@ -74,7 +74,7 @@ Authenticate to SMTP server with `:user` and `:pass`.
:to "foo@example.com"
:subject "Hi!"
:body "Test."})
{:code 0, :error :SUCCESS, :message "message sent"}
{:code 250, :error :SUCCESS, :message "250 Ok\n"}
postal.core>

#### Encryption (Gmail example)
Expand All @@ -98,7 +98,7 @@ anyway.)
:to "foo@example.com"
:subject "Hi!"
:body "Test."})
{:code 0, :error :SUCCESS, :message "message sent"}
{:code 250, :error :SUCCESS, :message "250 Ok\n"}
postal.core>

#### Amazon
Expand All @@ -113,7 +113,7 @@ you can only send *to* a verified address as well. Example:
:port 587}
{:from "me@draines.com" :to "me@draines.com"
:subject "Test from Amazon SES" :body "Test!!!11"})
{:error :SUCCESS, :code 0, :message "messages sent"}
{:code 250, :error :SUCCESS, :message "250 Ok 01020160ba715c7e-0268d4ae-4189-4020-80c0-23328e018775-000000\n"}
postal.core>

#### Attachments
Expand All @@ -132,7 +132,7 @@ Attachments and multipart messages can be added as sequences of maps:
{:type :inline
:content (java.io.File. "/tmp/a.pdf")
:content-type "application/pdf"}]})
{:code 0, :error :SUCCESS, :message "message sent"}
{:code 250, :error :SUCCESS, :message "250 Ok\n"}
postal.core>

If your attachment has a content-type that is not recognized by
Expand Down Expand Up @@ -212,25 +212,25 @@ You can stress-test a server by:

## Contributors

Allen Rohner
Andre Branco
Andy Fingerhut
Christoph Henkelmann
Colin Jones
Dante Briones
Dimas Guardado
Gerrit Hentschel
J. David Lowe
Jeff Palmucci
Joe Gallo
Kevin DeJong
Kyle Kingsbury
Paul Biggar
Paul Stadig
Phil Hagelberg
Roman Flammer
Sam Ritchie
Stephen Nelson
Allen Rohner
Andre Branco
Andy Fingerhut
Christoph Henkelmann
Colin Jones
Dante Briones
Dimas Guardado
Gerrit Hentschel
J. David Lowe
Jeff Palmucci
Joe Gallo
Kevin DeJong
Kyle Kingsbury
Paul Biggar
Paul Stadig
Phil Hagelberg
Roman Flammer
Sam Ritchie
Stephen Nelson

Copy link
Owner

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).

Copy link
Collaborator Author

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.

## License

Expand Down
17 changes: 14 additions & 3 deletions src/postal/smtp.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Copy link
Owner

Choose a reason for hiding this comment

The 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 send-single invocations, which could have an error. Likely want to return a vec here that the user can scan through.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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]
Expand Down