The tradition of sniffing the cork of a bottle of wine goes back to early 15th century Europe. The lack of food preservation meant that the meal was less than fresh. Diners would take the sweet-smelling corks from the wine bottles to plug their noses while they ate the spoiled food. As food quality improved, this action was transformed into merely sniffing the stopper to sample the aroma of the wine.
Source : Canter, Dee. Madeira, I Love You, 1964.