As someone who has hacked mail servers, written DNS servers, and come within 100 miles of typesetting, I'm going to throw in my vote that TeX addresses a much harder problem than qmail.
No contest there, but qmail is far from 'trivial'.
If you're going to compare qmail to something else though I think it should be compared to sendmail (or postfix for that matter), not to TeX.
Personally I think djb is a great coder, but there are quite a few of those around.
Programming is not a single-valued enterprise anyway, so best is a very hard to measure quantity, as good as meaningless. But I know 'bad' when I see it :)
The algorithms and pure theoretical CS in qmail actually is trivial. From what I remember, pretty much the only genuinely interesting thing in it is how he implemented his hash table.
From a systems programming perspective, qmail is not only nontrivial, but actually groundbreaking. His allocator design, the way he architected his libc replacement, the extent to which he takes advantage of bare-metal Unix programming (look at his queue notification mechanism), it's all really cool stuff.
But there's a big difference between theoretical CS and systems programming, and the parent commenter is right to point out that TeX is more complicated from a CS perspective than qmail is.