A monoid $M$ satisfies the universal mapping property (UMP) over $X$, if $X \subseteq M$ and for every map $\varphi : X \to N$, where $N$ is another monoid, there exists a unique homomorphism $\varphi : M \to N$ (i.e. this could be thought of as the extension of $\varphi : X \to N$, but this I want to show).
Now I want to show that if $M$ satisfies UMP over $X$, then $M$ is generated by $X$. First I thought that if this is not the case, then there exists some $m \in M$ such that $m$ is not a finite product of some elements from $X$, and this would contradict uniqueness of the homomorphism, as we could map $m$ onto any element from $X$, or to $1$. But in the first place this just gives a map, and it is not clear that this is also a homomorphism (see this related question).
So how to show that $X$ generates $M$?