The Recorder of York has warned that those who threatened MPs will receive heavy sentences.

Judge Sean Morris was jailing Sundas Alam for sending five “disgraceful, terrifying and shameful” emails in the same evening to her MP.

Bradford MP Naz Shah and her family had to flee their home in the middle of the night after Alam made threats including “do you want a bullet through your window or a rifle in your head”, a York jury heard last October.

“MPs dedicate their lives to the service of their constituents and their country,” said Judge Morris.

“They should not have to put up with threats. It should not be something that goes with the job.

He said; "There has to be an element of deterrence especially in the light of recent tragic events.

"Parliamentarians will be protected by the courts to ensure that others are deterred from their online threats and indeed physical threats.”

He jailed Alam, 30, of Princeville Street, Lidget Green, Bradford for three and a half years.

He said three people were wrongly arrested from their beds by armed police for sending the emails after Alam spoofed their emails to send the threats.

She let them give evidence before changing her plea to guilty on the third day of her trial to three charges of sending malicious emails and one of perverting justice.

The judge said she had planned that to distress one of the three, her former line manager at work.

In personal statements, the three victims spoke of the psychological and social impact of being arrested in the middle of the night “as if they were murderers, terrorists or drug dealers”.

“The trauma of that arrest can never be repaired,” said the wife.

They described how they had had to change their phones, cancel social media accounts, suffered the loss of their reputation at work and in the community, and planned to move home.

The judge made a 10-year restraining order banning Alam from contacting any of their family.

For Alam, Mark Barlow said: “The person she was intending to get at was not her MP but I accept that is what happened.”

Alam had had mental health issues at the time she sent the emails.

“She is in need of great assistance in order to deal with the issues,” he said, adding that two people were available to give her the treatment she needed.

The jury heard Alam had asked Ms Shah for help after she was sacked by West Yorkshire Community Rehabilitation Company for sending inappropriate messages to her line manager via its internal message system.

Ms Shah suggested she go to employment law solicitors. The judge said the advice was “quite correct”.

The jury heard how Alam had sent the emails late on April 3, four days after she was released under investigation suspected of harassing her former line manager online.

Detective Chief Inspector Andy Farrell, of Bradford District Police, said: “We welcome the sentence that Alam has received and hope it serves as a warning to others that threats towards public figures such as MPs are treated seriously and positive action will be taken to ensure offences are investigated thoroughly and robustly.

“West Yorkshire Police is committed to protecting members of the public from threats and harm and works closely with our MPs, to review their security arrangements and consider any additional safety concerns they may have.”