There's not enough information about your iMac, what version of macOS it's running, and how it's connected to the network/internet (WiFi? Ethernet?) in order to provide a detailed response.
See if this article from Apple helps with your issue. Be sure to check the section about running Wireless Diagnostics to check for network issues.
If your Mac doesn't connect to the Internet over Wi-Fi - Apple Support
Since you indicated that mail is no longer working too, you may be able to use the Mail app's Connection Doctor feature to help isolate where the issue is occurring. This article provides more detailed information:
Use Connection Doctor in Mail on Mac - Apple Support
If you continue to experience issues please provide additional information.