The reaction of alkanoyl halides with alcohols produces esters. The equilibria of this reaction are favored by eliminating the hydrochloric acid with a base (tertiary amine, pyridine)

reaction-halides-alkanoyl-alcohols
 
The mechanism occurs in two stages:
 
Stage 1. Addition of alcohol
 
reaction-halides-alkanoyl-alcohols
 
Stage 2. HCl removal
 
reaction-halides-alkanoyl-alcohols
 
Tertiary amines cannot form amides and give rise to alkanoyl ammonium salts, which is why they are suitable for removing the hydrochloric acid formed from the medium.