Breakdown of Te he mandado un código por mensaje.
un
a, an, some
el mensaje
the message
te
to you / yourself (reflexive) / you (direct object)
por
for / by / through / in (during a part of the day)
Questions & Answers about Te he mandado un código por mensaje.
Why do we use por instead of para here?
Could I use enviado instead of mandado?
Yes, absolutely! Both mandar and enviar mean to send, and they are perfectly interchangeable in this context. Mandar is very common in everyday spoken Spanish in Spain, while enviar can sound just a tiny bit more formal.
Why does the pronoun Te go right at the beginning of the sentence?
Te is the indirect object pronoun meaning to you. In Spanish, object pronouns must go directly before the conjugated verb. Here, the conjugated verb is the helping verb he, so Te has to go right in front of it. You cannot put it between he and mandado, nor can you attach it to the end of mandado.
Since this action is finished, why use the present perfect (he mandado) instead of the simple past (mandé)?