The "three sites per nucleotide" (3SPN) model provides a coarse-grained representation of nucleic acids for simulation of molecular processes. Previously, this model has relied on an implicit representation of the surrounding ionic environment at the level of Debye-Hückel theory. In this work, we eliminate this limitation and present an explicit representation of ions, both monovalent and divalent. The coarse-grain ion-ion and ion-phosphate potential energy functions are inferred from all-atom simulations and parameterized to reproduce key features of the local structure and organization of ions in bulk water and in the presence of DNA. The resulting model, 3SPN.1-I, is capable of reproducing the local structure observed in detailed atomistic simulations, as well as the experimental melting temperature of DNA for a range of DNA oligonucleotide lengths, CG-content, Na + concentration, and Mg 2 + concentration.