How to attach a file with a password to an e-mail

I would like to create a functionality to send a PDF file generated with a document template as an attachment of a mail. However, I am not sure how to do this as follows. 1. Since Generate Document does not have ReturnValue, I want to save it somewhere Entity, but I have not found a method yet. 2. Create a JavaAction to generate a password and determine whether it can be set as a file password. Does anyone know how to do? Thanks in advance.  
1 answers

Question 1: If you generate a document using a document template you need to put a FileDocument type entity or inheritence of FileDocument in to the 'generation' action as a file.  Mendix saves the document in this entity and you could use this as attachement in your email.