Stephen Cruz, 34, used the "contact us" form on the Police Scotland website to repeatedly send threatening and abusive messages.
He said he was going to slit the throat of the First Minister and went on to make derogatory and racist remarks about the Queen.
He even told police officers that three letter bombs were going to go off at Armed Forces career offices in cities across Scotland.
Cruz, a prisoner at HMP Grampian, appeared at Aberdeen Sheriff Court yesterday where he admitted the charge against him.
Court papers state that Cruz behaved in a threatening and abusive manner likely to cause a reasonable person to suffer fear or alarm.
He sent the messages between January 20 and March 6 while travelling between St Peter's Court, Peterhead, and the Gallowgate area of Aberdeen.
The court heard on March 6 he intimated to officers that three letter bombs had been sent to Armed Forces recruitment offices in Aberdeen, Dundee and Edinburgh.
He claimed they were going to detonate on the same day.
Cruz was remanded in custody and will appear again for sentencing next month.