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)

The mechanism occurs in two stages:
Stage 1. Addition of alcohol

Stage 2. HCl removal

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.