Answer: Rambam (Mezuza 5:6) and the Shulchan Aruch (YD 289:4) write that one should hang the mezuza either with nails or by placing it into a hollow in the doorpost.
R’ Menashe Klein (Mishne Halachos 4:140:12) notes that many people fix their mezuzos with glue, thereby not fulfilling the mitzva to attach a mezuza. Glue has a tendency to dry out causing the mezuzos to fall.
Nonetheless, other poskim understand nails to be an example of fastening the mezuza well. Thus, the Aruch Hashulchan (YD 289:15) writes that if one wraps the mezuza well and then sticks that wrapping or case firmly with glue, that is as good as nails.
R’ Mordechai Yaakov Breisch (Chelkas Yaakov YD 164), R’ Yitzchak Yaakov Weiss (Minchas Yitzchak 7:72:3) and R’ Ovadia Yosef (Yechave Daas 6:58) all quote the Aruch Hashulchan as well as the Nimukei Yosef (Bava Metzia 102a) who writes that one can use either nails or sticky lime.
In conclusion, one can use anything to attach one’s mezuza to their doorpost providing that it is firmly attached.