The interaction of a melamine molecule with a carbon nitride nanotube (CNNT) was explored by means of dispersion-corrected density functional calculations. It was found that melamine prefers to be adsorbed on the porous site of the tube wall with the adsorption energy of -21.9 kcal/mol. This adsorption process significantly shifts the HOMO of the tube to higher energies, thereby reducing the gap of the tube from 3.97 to 2.65 eV. Moreover, the work function is slightly decreased which can facilitate the field electron emission from the tube surface. It is expected that CNNT can be a promising candidate for sensor devices in detecting the melamine molecule with short recovery time and high sensitivity.