Can. 996
© Libreria Editrice Vaticana Source: vatican.va
§1. To be capable of gaining indulgences, a person must be baptized, not excommunicated, and in the state of grace at least at the end of the prescribed works.
§2. To gain indulgences, however, a capable subject must have at least the general intention of acquiring them and must fulfill the enjoined works in the established time and the proper method, according to the tenor of the grant.
Read the whole title TITLE IVThe Sacrament of Penance 959–997