Katy Perry and John Mayer exchanged love letters before they started dating.

The 'Roar' hitmaker has revealed she and the singer-songwriter, 36, ''had a long courtship'' before they first went public with their on/off relationship in June 2012, and it inspired her new track 'Legendary Lovers.'

The 29-year-old star told Entertainment Weekly magazine: ''I actually wrote it in an email one time, and after I wrote it I looked -- we had a long courtship before anything was [public], just writing letters to each other -- and seeing 'legendary lovers,' it sounded so nice. Some things float into my mind, and I process them, and [then] I make songs about them.''

The song, which features on her new album 'Prism,' includes the lyrics: ''I never knew I could see something so clearly looking through my third eye. Never knew karma could be so rewarding and bring me to your life/ Maybe this is the beginning of something so magical tonight.''

Katy, who was married to Russell Brand for 14-months until December 2011, previously revealed that she had a huge crush on John before they got together.

She recently said: ''I actually am dating my crush. I had a crush on him for a long time, and it just so happens we fit together great.''