drewr / postal

Clojure email support
MIT License
587 stars 85 forks source link

Don't use hardcoded sendmail paths #34

Closed goblin closed 10 years ago

goblin commented 11 years ago

Why don't you just use the sendmail that's in $PATH?

I happen to use msmtp for outgoing mail and exim for local delivery... The way you've done it is it'll try to use exim (because that's what /usr/sbin/sendmail is symlinked to), and fail.

Also my msmtp is in /usr/bin not /usr/sbin.

drewr commented 11 years ago

I guess the short answer is that historically there's no way to predict where sendmail will live. It used to be commonly found in /usr/lib, for example, which wouldn't be in a default $PATH.

I'm open to a more fine-grained solution here. What should I look for in $PATH, msmtp or sendmail? Or maybe just look for $SENDMAIL and bypass the lookup altogether?

goblin commented 11 years ago

Yeah, historically it's a mess... I don't know what's the best way to fix it.

If it was me, I'd:

  1. check the $SENDMAIL env var
  2. check for msmtp in $PATH
  3. check for sendmail in $PATH
  4. check for msmtp in "known locations" (/usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin)
  5. check for sendmail in "known locations"

The reason I'd prefer to look for msmtp first is that if someone has msmtp installed, he's more likely to use it for outgoing mail. But then again there can easily be multi-user servers which have both installed and users might prefer to use one over another. Checking the env var would allow them to fairly easily set what they want to use, hence the top priority.

But this may be far from ideal...

drewr commented 11 years ago

Typically when someone is using msmtp, the machine is outbound-only, and thus only care about msmtp. In this case, sendmail is usually a link to the msmtp binary. At least, this is how I've operated for a while.

But I agree, this assumption doesn't work for everybody. Let's start with a $SENDMAIL option that will force postal to use it.

drewr commented 11 years ago

I pushed 1.10.4 with this change. See how it works for you.

rlbdv commented 10 years ago

I think we might like to be able to just specify the sendmail path explicitly (disabling the auto-search), perhaps via a :sendmail option. Plausible? Otherwise we'd be stuck with an app wrapper that sets SENDMAIL (since you can't modify System/getenv) -- and then we couldn't change the path during a server's lifetime.

the-kenny commented 10 years ago

Not being able to set this programmatically is a major annoyance right now. Please support either setting it via a dynamic binding, search in PATH or allow me to pass it as an optional argument to sendmail-send.

drewr commented 10 years ago

I agree we should add more dynamicity here. As a workaround could you symlink to /usr/sbin/sendmail? Runtime changes would just involve changing the link. Not ideal, will address it internally eventually.

rlbdv commented 10 years ago

If allowing a single string isn't sufficient, I suppose you could just have the hypothetical :sendmail option accept a function that returns the desired value (i.e. "/sendmail/you/want").

drewr commented 10 years ago

Released 1.11.2. Thanks @the-kenny @rlbdv!