The Scottish Environment Protection Agency (Sepa) advice came as figures reported by The Ferret news website showed more than half of Scotland’s most popular beaches were contaminated with sewage in breach of safety limits this summer.
A total of 49 of 87 designated bathing waters recorded levels of faecal bacteria since May that could endanger health.
The Ferret said heavy rain had caused public sewers to flood and washed animal faeces off the land, resulting in water concentrations of bacteria that could cause stomach, ear, nose and throat infections.
The Sepa figures showed the worst contamination, of more than 50 times the limit, was in June at Eyemouth in the Borders and at Lower Largo in Fife.
There were also high bacteria levels detected at Ettrick Bay on Bute, West Sands at St Andrews, Seafield at Kirkcaldy and Harbour Beach at Kinghorn, Broad Sands and West Beach, near North Berwick, and Belhaven Beach in Dunbar.
Sepa urged bathers to make an “informed choice” about swimming.
It said regularly updated advice was available on its website and on electronic signs at 29 beaches.
Its spokesperson said: “Bathing is not advised during or one-two days after heavy rainfall.
“This is due to the risk to bathers’ health from water pollution.”
Calum Duncan, head of conservation in Scotland for the Marine Conservation Society, said: “It is crucial we understand when and why samples fail, and if they arise from combined sewer overflows, where the sewer network is only meant to overflow into rivers and coastal waters after extremely heavy rain.”
The Sepa spokesperson said: “The most common causes of water quality issues in Scotland are short-term pollution following heavy rainfall, which can cause sewer overflows, agricultural run-off from land, and surface water discharges [such as] from roads, car parks, and pavements.
"This means bacteria from dog fouling and from gulls can also be factors.
“Scotland’s bathing water quality is the best it has been since 2015, when tighter standards first came into force.
"Sepa continues to work with partners to raise or maintain the state of bathing waters throughout the country for the benefit of the communities and visitors who use them.”
The agency has asked Scottish Water to install spill monitors on all the sewer overflows that discharge to designated bathing waters by the end of 2024 to help prioritise investment.
Scottish Government-owned Scottish Water said it had installed spillage meters at 354 of its 3,600 sewage overflows and planned another 1,000 by the end of 2024 where the risks were highest.
However, it pointed out some sewers were designed to overflow in bad weather.
Waste water manager Andy Mortali said: “During some of the intense summer storms that we have had, we expect combined sewer overflows to spill and bathing water performance to be at risk from these discharges and from other run-off.
“Climate change, and more variable and extreme weather, present a challenge, but we will continue to work with partner organisations to improve bathing water quality where required.”
However, he said there was no evidence the bathing water results were due to “Scottish Water assets not performing”.