The order ID is generated by the store order summary behavior.
The Code to send the email is at lines 363 - 448
the store order summary code happens after the email is sent at lines 449 - 509
this needs to be re arranged so the email is sent after the order summary is stored.