A Trojan is used to carry out ransomware attacks
A Trojan is disguised as a legitimate file.
Hence a user gets tricked.
He thinks the file is OK and harmless.
He downloads it.
And opens it when it arrives as an email attachment.
However nowadays high profile example of Trojan called WANNACRY WORM has been made by Hackers.
This can travel automatically between computers without any user interaction.
Reference - HTTPS://en.wikipedia.org/wiki/Ransomware