Humans aren't the only animals that have to guard against potential infection during sex. Fruit flies are at greatly increased risk of infection during their mating season, which is why the male's mating call actually boosts the female's immune system.
Researchers at the University of St. Andrews played recordings of male mating calls for a bunch of female fruit flies. These calls are produced by the male vibrating his wings, and they serve as a signal to females that mating season has begun. Intriguingly, the mating call isn't just a behavioral cue - the sound of it actually activated a bunch of genes in the female fruit fly to prepare her for mating.
Most of the genes that are activated by the mating call are just there to indicated the female was excited at this prospect - the genes associated with the female's antennae, which are basically her ears, were very strongly activated. However, that wasn't the only genetic response, as Professor Mike Ritchie explains:
"But the big surprise was that genes involved in immune function were also switched on. It appears that if she hears a sexy song, she knows she's likely to mate soon, so she makes the physiological change to prepare for mating - that involves [increasing the activity of] immune genes."
It appears that females evolved this genetic response to deal with the often traumatic experience of mating. In many insect species, the mechanics of sex are fairly violent, and damage to the female's genital tract is common. While fruit fly sex isn't quite that dangerous, this particular adaptation probably goes back to a point in their evolutionary past when such trauma - and any subsequent infections from the wounds - were commonplace.
Professor Mike Siva-Jothy of the University of Sheffield explains that this fruit fly immune response may just be a more obvious example of a fairly common insect adaptation:
"This is an extreme example, but often, looking at extreme examples sheds light on what's going on in many species. My proposal is in any situation where you have predictable exposure to pathogens, you might expect females to anticipate the damage and...to respond. It's an idea that meshes very nicely with what [this study] has shown."