If you have an OS X 10.6 Snow Leopard retail upgrade DVD (the one with the cat on the label), then install Snow Leopard to that Mid-2009 iMac. I'm not sure the OS X 10.5 Leopard Restoration DVD which originally shipped with the iMac will work (I've seen some mention many years ago that 10.6 was required, but if you don't have the 10.6 Upgrade DVD, then certainly try the original Restoration DVD).
Then, using any other computer (even Windows or Linux) that can access the Internet you can download the macOS 10.11 El Capitan installer directly from Apple from outside the App Store. Transfer the downloaded El Capitan DMG file to the iMac running OS X 10.6. Extract the El Capitan installer & run it on the Mid-2009 iMac to upgrade to macOS 10.11. Unfortunately a Mac compatible with El Capitan is required to extract & run the El Capitan installer.
Here is an Apple article with instructions for downloading and extracting the El Capitan installer to the Applications folder:
How to download and install macOS - Apple Support