Human rights lawyers claim that Sina Dehghan, who was just 19 when he sent the messages, was tricked into signing his own death warrant after being persuaded to confess to the breach of Islamic law with the promise of release if he did so.
But after obtaining a confession, prosecutors dropped the agreement and sentenced Dehghan to death in January this year, according to the Centre for Human Rights in Iran.
The content of the messages, said to have been sent using the Line app, is unknown.
A source told CHRI: “During his interrogation, Sina was told that if he signed a confession and repented, he would be pardoned and let go.
“Unfortunately, he made a childish decision and accepted the charges. Then they sentenced him to death.”
His family was allegedly told if they kept quiet about the charges, he was more likely to go free.
Prosecutors asked that Dehghan be sentenced to death for “insulting the prophet' as well as to 16 months in prison for 'insulting the supreme leader'.
The sentence has now been upheld by the country’s Supreme Court, according to the CHRI, although a request for a judicial review has given his family hope that his life could still be spared.
His mother said in a video interview obtained by CHRI: “According to Sina's lawyer, steps have been taken for a judicial review, and with the good news we're hearing from him, God willing this case will come to end positively as soon as possible.”
Co-defendants Sahar Eliasi and Mohammad Nouri were also convicted of posting anti-Islamic material on social media.
Nouri was issued a death sentence, but it is unknown if the Supreme Court has given its final ruling.
Eliasi had his seven-year prison sentence reduced to three on appeal.
Dehghan was undertaking compulsory military service at the time of his arrest in 2015 and had just four days left to serve.
Japanese-based Line has since added end-to-end encryption to its messages, although it is not known how they came to be seen by the authorities.
“They took him to his home and searched it while he repeatedly expressed regret and repentance,” the unnamed source told CHRI.
The source added that Dehghan is struggling to cope with the incarceration in Arak Prison.
“Sina is not feeling well. He’s depressed and cried constantly. He’s being held in a ward with drug convicts and murderers who broke his jaw a while ago.
“He was a 19-year-old boy at the time (of his arrest) and had never done anything wrong in his life.”
Iran is believed to execute more people per capita than any other country. According to Amnesty International, there were 289 state executions carried out in Iran in 2014, the majority of which (up to 74 per cent) were for drugs-related offences.
The number of executions in the Islamic fundamentalist country is reported to be on the rise and according to the UN, at least 966 people were put to death in the country in 2015.
Iran has attracted widespread condemnation for carrying out executions of minors, despite having signed the UN convention on the rights of the child.
The usual method of execution is hanging, although the country has been heavily criticised for its occasional practice of stoning women to death, usually for adultery. According to Amnesty, public executions still occasionally take place, despite being banned in the country in 2008.
According to Iran's Islamic penal code, insulting the prophet is punishable by death, although a clause states if the accused states the insults were the result of a mistake or were made in anger, the sentence can be reduced to 74 lashings of the whip.
Human Rights organisation Article 19 said of Dunham: “He is now on death row, yet the imminence of the execution of Sina is an affront both to international standards and Iran’s own criminal code.
“It is also clear that Sina was only given access to a court-appointed lawyer, who failed to adequately defend him in trial.”
It added that the death penalty imposed on Dehghan and others illustrate how individuals are “at the mercy of a system where forced confessions, false promises, and threats to family members undermine not only national judicial processes, but the international standards Iran has signed up to.
“Iranian authorities have an opportunity to act to stop the execution, and to take visible steps to implement their own codes of practice. We ask simply that a review of the case be undertaken immediately and the death penalty dropped.”