Mail merge dates to early word processors on personal computers, circa 1980. WordStar was perhaps the earliest to provide this, originally via an ancillary program called MailMerge. WordPerfect also offered this capacity for CP/M and MS-DOS systems, while Microsoft Word did so later.
Now used generically, the term "mail merge" is a process to create personalized letters and pre-addressed envelopes or mailing labels mass mailings from a form letter – a word processing document which contains fixed text, which will be the same in each output document, and variables, which act as placeholders that are replaced by text from the data source.
The data source is typically a spreadsheet or a database which has a field or column for each variable in the template. When the mail merge is run, the word processing system creates an output document for each row in the database, using the fixed text exactly as it appears in the template, but substituting the data variables in the template with the values from the matching columns.