using templates for attachments inside a message; code refactoring