Rabbi Nachman teaches,
The main cause of attacks of lustful cravings is depression. You should therefore make every effort to be happy at all times.
Even if you fall into thick mud and find it extremely hard to escape, just scream and scream and scream.
Some people also worry over the very fact that they have such thoughts. But “Trouble is bad enough when it comes” ( Berachot 9b) . There is no need to let the fact that you have such thoughts disturb you, whether because you have had an attack of them in the past or because you fear they may strike again in the future.
Sichot Haran #129
With permission taken over from: Daily Dose Of Rabbi Nachman