You asked

​Would it be possible to get a list of all UK postcodes with the corresponding towns and counties?

We said

We maintain a number of products that allow you to look-up between postcodes and a range of administrative geographies including counties, local authorities, wards and parishes.

These are available at no charge via our Open Geography portal.

ONSPD

NSPL

Dependant on the purpose of this requirement it may be that the allocation of postcodes to the relevant local authority / borough may be sufficient.

Since there is no fixed definition of 'towns' or 'urban areas' we do not currently maintain a separate postcode to 'town' lookup.

Postcodes are linked to 'postal towns' for mail delivery purposes and Royal Mail would be the best source for this information.