It is not permissible to inseminate a woman with the sperm of a non-maḥram man, other than her husband.
Question: Is it permissible for a woman, whose husband is sterile, to be artificially inseminated with sperm from a nonmaḥram man (other than her husband), i.e., through placing the sperm in her womb?
Answer: In itself there is no legal impediment to inseminating a woman with the sperm of a non-maḥram man. However, it is obligatory to avoid the preliminary steps which are ḥarām, such as looking and touching. It is not permissible to inseminate a woman with the sperm of a man, other than her husband, irrespective of whether or not she was married. It makes no difference whether husband and wife consented to the act or not. Likewise, if insemination is done by the husband or another man.
1. Ayatollah Seyyed Ali Khamenei, Newly Asked Questions, Medical Issues 4.
2. Ayatollah Seyyed Ali Sistani, Question & Answer, artificial insemination 3.