Set custom headers to Accounts sendenrolmentemail


i need to set custom headers for every enrollment email i send with Accoounts.
this is how i did it:
var previousHeaders = Accounts.emailTemplates.headers;
Accounts.emailTemplates.headers = {‘X-Mailgun-Variables’: JSON.stringify({ programId: programId, applicantId: applicant._id }) };
Accounts.emailTemplates.headers = previousHeaders;

is there any other way to do this?
is there guarantee that this code will run synchronously? in case of many enrollments i might run over headers because it is global.