Formation of complex organic molecules via ion-molecule reactions in extraterrestrial environments