All sorts of thoughts can happen to us out of the blue…
the fact that a though happened to one-
does not mean per se there was any sin.
And for mortal sin one needs not only grave matter, but full knowledge and deliberate (complete) consent…
(And some need some medical/professional assistance in this area…such as medication etc )
Now…
For the next few moments --try real hard NOT to think of Apple.
then scroll down.
What did you think of?
An apple.
Even though your will was against it -you did not want to think of an apple.
Now back to thoughts of blasphemy …
The best thing to do with such thoughts is not to fight them directly --not fear that they will come…do not consent and simply and calmly turn to something else…(or it may be best to keep doing the good thing one is doing…like they come out of the blue when your at work …keep working …etc)
Ignore such unwanted thoughts like one would ignore a hissing goose or a barking dog. One does not stop to argue with a hissing goose or a barking dog does one? No one keeps on walking…and at most laughs at them…
(as noted above the image there comes from a Carthusian Monk from centuries ago…)
(PS: having such thoughts happen to one could involve scrupulosity …or it may not…one can suggest a “regular confessor” who can come to know one and assist one)