Rebekah Brooks sent an effusive text message to David Cameron on the eve of his 2009 party conference speech, telling him: "Professionally, we're definitely in this together!" and signing off: "Yes he Cam!"

Brooks sent the text on 7 October 2009 during the Conservative party conference, a week after the Sun had switched allegiance to the Tories on the eve of then prime minister Gordon Brown's Labour party conference speech. At the time, Brooks was chief executive of the Sun's parent company, News International, and Cameron was still leader of the opposition.

"I am so rooting for you tomorrow not just as a proud friend but because professionally we're definitely in this together!" wrote Brooks. "Speech of your life! Yes he Cam!"

Brooks's sign-off was repeated the following day in the headline on the Sun's leader comment, heaping praise on Cameron's speech.

Cameron, appearing at the Leveson inquiry on Thursday, said the text referred to the fact his party and Brooks's newspapers would be "pushing the same agenda".

"I think that is about the Sun had made this decision to back the Conservatives, to part company with Labour, and so the Sun wanted to make sure it was helping the Conservative party put its best foot forward, with the policies we were announcing, the speech I was going to make and all the rest of it, and I think that's what that means," he added.

"I think what it means was that we were, as she put it, … friends, but professionally we – as leader of the Conservative party and her in newspapers – we were going to be pushing the same political agenda."

Robert Jay QC, lead counsel to the inquiry, said the first part of the text had been redacted because it was not relevant. Jay added that it probably included a joke, as Brooks's message continued: "But seriously I do understand the issue with the Times. Let's discuss over country supper soon.

"On the party it was because I had asked a number of NI people to Manchester post-endorsement and they were disappointed not to see you. But as always Sam was wonderful – (and I thought it was OE's that were charm personified!)."

"OE" is thought to refer to "Old Etonian".

Asked about the text by Jay, Cameron said: "The issue with the Times was that at the party conference I had not been to the Times party.

"The major newspaper groups tend to have big parties at the party conference and they expect party leaders, cabinet ministers, shadow cabinet ministers to go, and that would be the normal thing to do, the Telegraph, the Times, others would do this.

Jay asked if the "country supper" reference was "the sort of interaction you often had with her?" The prime minister replied: "Yes, we were neighbours."

Earlier, Jay asked Cameron at what point he had begun to count Brooks as among his "good friends". Cameron said he was reluctant to be specific because he could not remember and did not want to get it wrong.

"We got to know each other because of her role in the media, my role in politics, but we struck up a friendship. Our relationship got stronger when she married Charlie Brooks, who I've known for some time and who's a neighbour," he added.

Asked if the two were in contact on a weekly basis by 2008 and 2009, as Brooks's evidence to the inquiry suggested, Cameron said: "It's very difficult because I don't have a record and I don't want to give you an answer that isn't right.

"Sometimes I expect we would have been talking to each other quite a bit, particularly around the time perhaps of the wedding or when we were both in Oxfordshire, we would have had more frequent contact.

He added: "Particularly once she started going out with Charlie Brooks, living a couple of miles down the road, I was definitely seeing her more often because of my friendship with Charlie as a neighbour and Charlie and I played tennis together and all sorts of other things."