I understand, and the material linked above describes how to go about that using JavaMail. Was there anything in particular you didn't understand about that? What have you tried so far?
Of course, as the JavaMail FAQ points out, not all servers support DSNs, in which case you have to go about the problem in the ways mentioned in the other
thread where you asked about this.