Background Depression is a prevalent mood disorder. Women face a heightened risk of depression during pregnancy and after childbirth, which can have negative consequences for both the mother and her family. It is essential to explore preventive strategies. Objective To assess the impact of education focused on health-promoting behaviors in preventing postpartum depression (PPD) through social messaging among pregnant women. Methods This randomized controlled trial study involved 108 non-depressed eligible pregnant women with a gestational age of 28-30 weeks during 2022-2023. Participants were randomly assigned to intervention and control groups using a block randomization method. The intervention group received virtual education based on health-promoting behaviors weekly over six sessions. The Edinburgh Postnatal Depression Scale (EPDS), Patient Health Questionnaire-9 (PHQ-9), and Health Promoting Lifestyle Profile II (HPLP II) questionnaires were utilized to evaluate outcomes. Data analysis was performed using SPSS software version 23, with a significance level set at P < 0.05. Results The mean differences between the scores of EPDS, PHQ-9 and HPLP II before and after the intervention in two groups were - 4.85 (CI95%= -3.22, -6.48), -6.22 (CI95%= -4.43, -8.00) and 28.22 (CI95%= 23.41, 33.03), respectively, which were statistically significant (P < 0.001). The findings regarding the dimensions of health-promoting behaviors also indicated that all dimensions increased significantly in the intervention group. The greatest and least amount of change was observed in the physical activity dimension at 5.50 (CI95%= 4.31, 6.68) and in interpersonal relations at 3.48 (CI95%= 2.24, 4.72), respectively. The number needed to treat (NNT) for depression, based on the Edinburgh questionnaire six weeks postpartum was approximately 2.571, indicating that nearly one in two mothers who received education benefited. Conclusion The app-based health-promoting behaviors intervention-benefiting from not requiring in-person referrals and providing a common platform for communication-is effective in enhancing health-promoting behaviors, reducing depression scores and decreasing the frequency of PPD. In other words, this type of intervention led to the prevention of postpartum depression and the promotion of health-promoting behaviors among pregnant women. Registration The study was retrospectively registered with the IRCT Registry on 31/05/2024 (registration number: IRCT20221109056451N2).