-
Notifications
You must be signed in to change notification settings - Fork 85
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
Return the reply from SMTP server when sending single message #92
base: master
Are you sure you want to change the base?
Conversation
Return the reply because it may contain useful information for logging and tracking. In particular, Amazon SES insists on assigning a new Message ID rather than trusting the one we send them, and they return the assigned Message ID in the reply, after "250 Ok". Only do this when `smtp-send` is called with a single message. (This is the common use case, which is documented and supported by postal.core.) If someone manages to call `smtp-send` with multiple messages, then return a response without the server replies, as before. (The alternative, which is to complicate the response from `smtp-send` to incorporate multiple replies while remaining backwards compatible, does not seem worth it---especially because sending multiple messages at a time is not something you should do if you care to know which ones succeeded.)
src/postal/smtp.clj
Outdated
|
||
(defn- send-multiple [transport jmsgs] | ||
(doseq [^javax.mail.Message jmsg jmsgs] | ||
(.sendMessage transport jmsg (.getAllRecipients jmsg))) |
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.
Why not reuse send-single
here?
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.
Ah, yes, that's be fine. I'll change that.
This is great, thanks @ljosa! Left a question but otherwise looks good. |
Phil Hagelberg | ||
Roman Flammer | ||
Sam Ritchie | ||
Stephen Nelson | ||
|
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.
(defn- send-multiple [transport jmsgs] | ||
(doseq [^javax.mail.Message jmsg jmsgs] | ||
(send-single transport jmsg)) | ||
{:code 0 :error :SUCCESS :message "messages sent"}) |
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.
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.
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.
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.
b199c5a
to
382cb0e
Compare
Return the reply because it may contain useful information for logging
and tracking. In particular, Amazon SES insists on assigning a new
Message ID rather than trusting the one we send them, and they return
the assigned Message ID in the reply, after "250 Ok".
Only do this when
smtp-send
is called with a single message. (Thisis the common use case, which is documented and supported by
postal.core.)
If someone manages to call
smtp-send
with multiple messages, thenreturn a response without the server replies, as before. (The
alternative, which is to complicate the response from
smtp-send
toincorporate multiple replies while remaining backwards compatible,
does not seem worth it---especially because sending multiple messages
at a time is not something you should do if you care to know which
ones succeeded.)