Python mail-merge script with "if" and group functionality