Fix emailtemplate query