Although it is well known that mating increases the risk of infection, we do not know how females mitigate the fitness costs of sexually transmitted infections (STIs). It has recently been shown that female fruitflies, Drosophila melanogaster, specifically upregulate two members of the Turandot family of immune and stress response genes, Turandot M and Turandot C (TotM and TotC), when they hear male courtship song. Here, we use the Gal4/UAS RNAi gene knockdown system to test whether the expression of these genes provides fitness benefits for females infected with the entomopathogenic fungus, Metarhizium robertsii under sexual transmission. As a control, we also examined the immunity conferred by Dorsal-related immunity factor (Dif), a central component of the Toll signalling pathway thought to provide immunity against fungal infections. We show that TotM, but not TotC or Dif, provides survival benefits to females following STIs, but not after direct topical infections. We also show that though the expression of TotM provides fecundity benefits for healthy females, it comes at a cost to their survival, which helps to explain why TotM is not constitutively expressed. Together, these results show that the anticipatory expression of TotM promotes specific immunity against fungal STIs and suggest that immune anticipation is more common than currently appreciated.