The potential of near-infrared spectroscopy to measure fat, total protein, and lactose contents of unhomogenized milk was studied for use in dairy management, as a new tool for on-line milk analysis in the process of milking. Influence of the spectral region, sample thickness, and spectral data treatment on the accuracy of determination was investigated. Transmittance spectra of 258 milk samples, collected at different stages of the milking process, were obtained with a spectrophotometer (NIRSystems 6500; FOSS-NIRSystems, Silver Spring, MD) in the wavelength range from 400 to 2500 nm with sample thicknesses of 1 mm, 4 mm, and 10 mm. The spectral region and sample thickness were found to be significant factors for milk fat and total protein determination but not the lactose determination. The best accuracy was obtained with the 1100 to 2400 nm region, 1-mm sample thickness, and the first derivative data transformation. For the spectral region from 700 to 1100 nm, close accuracy was obtained for fat with a 10-mm sample and for total protein with a 1-mm sample thickness. The sample thickness did not change significantly the accuracy of lactose determination. Different treatments of spectral data did not improve the calibrations for fat and protein. For the region from 700 to 1100 nm, where inexpensive on-line sensors could be used, the highest positive coefficients for fat were at 930, 968, 990, 1026, 1076, and 1092 nm; for lactose were at 734, 750, 786, 812, 908, 974, 982, and 1064 nm; and for total protein were at 776, 880, 902, 952, and 1034 nm.