Female moths produce a sex pheromone, a different blend of chemicals for each species, which attracts males from a distance.
Males detect these chemicals with exquisitely sensitive hair-like structures in the antenna. These hairs contain specialized neurons, nerve cells that express pheromone receptors which are activated when they bind to individual pheromone components.
Different species have different pheromone receptors, and so the ability to most accurately smell females of the same species prevents attraction to other females.
Solving the puzzle of why a certain pheromone receptor is activated only by a specific chemical has motivated much past research.