I'm doing some tasks I wonder what is the difference between from and by. Is there some definition when to use them or are both equivalent for some cases? e.g This is nice letter by/from him.
English prepositions are notoriously difficult for non-native speakers - not least because even most native Anglophones would be initially be tempted to simply say a letter by him and a letter from him are effectively equivalent (it's just that in practice, from is far more common).
But there is often some "method in the madness", as can be illustrated by considering different possible contexts. Suppose a history teacher is presenting some of Winston Churchill's private correspondence to his class, to give them an "inside view" on how he came to be Britain's wartime leader (I know today he might be more likely to have them watch the movies Churchill and Our Darkest Hour, but we'll just ignore that).
I can say with absolute certainty that my hypothetical teacher would be far more likely to say In today's lesson we're going to look at several letters [written] by Churchill rather that ...letters [sent] from Churchill. But explaining exactly why is rather more difficult...
Part of the answer is that a letter from X usually implies a letter sent from X to the speaker as the intended recipient (or whoever he's speaking to, as in Here's a letter from your sweetheart). That's because the preposition from is inherently evocative of something (a communication, here) being transferred from one place / person to another.
On the other hand, by more naturally alludes to the source / mechanism whereby something came to exist. Obviously Churchill wasn't writing to either the teacher or his students - what matters to the teacher is that Churchill wrote them, and in the context of his lesson, by exactly conveys that.