This study aimed to identify the causal effect of breastfeeding on postpartum depression (PPD), using data on mothers from a British survey, the Avon Longitudinal Study of Parents and Children. Multivariate linear and logistic regressions were performed to investigate the effects of breastfeeding on mothers' mental health measured at 8 weeks, 8, 21 and 32 months postpartum. The estimated effect of breastfeeding on PPD differed according to whether women had planned to breastfeed their babies, and by whether they had shown signs of depression during pregnancy. For mothers who were not depressed during pregnancy, the lowest risk of PPD was found among women who had planned to breastfeed, and who had actually breastfed their babies, while the highest risk was found among women who had planned to breastfeed and had not gone on to breastfeed. We conclude that the effect of breastfeeding on maternal depression is extremely heterogeneous, being mediated both by breastfeeding intentions during pregnancy and by mothers' mental health during pregnancy. Our results underline the importance of providing expert breastfeeding support to women who want to breastfeed; but also, of providing compassionate support for women who had intended to breastfeed, but who find themselves unable to.