Add attachment template and revise email encode function.