OpenCDSS / cdss-lib-processor-ts-java

Colorado's Decision Support Systems (CDSS) time series processor library (Java)
GNU General Public License v3.0
0 stars 1 forks source link

Need to complete SendEmailMessage command #96

Open smalers opened 3 years ago

smalers commented 3 years ago

The SendEmailMessage command has been started and needs to be finished to satisfy a project to monitor SNODAS website data. In that system, a system process is going to be run to check that the software is properly creating output. A check-in email will be sent on some frequency by running the check as a cron process. The command uses a Java API so hopefully there are no issues with that. In addition to implementing typical email handling capability, the main issue is how to avoid using public credentials in command files. We at least need to evaluate how to do some basic authentication to support interactive and automated use. Some thoughts are:

  1. Use a system call:
    1. Configure email on the Windows 10 machine so that authentication is handled by the operating system.
    2. Similarly, use Linux with sendmail, mail or other program so that email authentication is handle by operating system
    3. This would involve using built-in TSTool functionality to make a system call, such. See the RunProgram, RunR, and other commands. The TSTool command would need to take input from the command and put together the proper system call.
    4. The command would need parameters, perhaps on a separate tab, to specify the email program to call.
  2. Connect to an SMTP server via the Java API. The problem is that this requires authentication and don't want to have password in plain text in the command file, especially for automated processes. The initial work is focusing on automation so maybe a less important robot email account can be used to minimize risk to unwanted use. The following are ideas for how to secure the credentials:
    1. Use a plain text file that is protected by user login. This is the concept of PostgreSQL .pgpass configuration file. It has mode 600 on Linux meaning that only the owner can see. Then the software needs to be told to use. On Windows, the file would be saved in the user's data so would only be cracked if someone broke into their account.
    2. Use some other approach such as environment variable to pass the password. TSTool uses this with ReclamationHDB datastore - see the SystemLogin and SystemPassword property descriptions. Using a prompt may be OK if the task is actually run interactively (DO NOT LOG THE PASSWORD in log messages or other output).
    3. Something else?

We just need to get this working at some functional level. All examples should be documented in Markdown so they can be folded into the TSTool command documentation.

smalers commented 3 years ago

Here is my feedback based on discussions with Josh and the pull request.

  1. I need a Markdown file to review for documentation. I'll try my best to recommend other actions without having that to work from.
    1. The subject matter is too complex to deal with through repo comments and we need to converge on actual documentation ASAP appropriate for users and for my review.
    2. Edit the existing command documentation similar to other command documentation so that I can respond to that and insert my own information.
    3. Add sections in the overview to explain each mail program approach including necessary software installation and configuration. Link to other documentation. List command parameters that are needed, as described below.
    4. See the sendmail program as an option for using sendmail on Windows but could also try on Cygwin (but don't want to spend a bunch of time on that).
  2. Implement a tabbed interface for the command parameters so that additional parameters can be added without overwhelming the user. Ideally if we can demonstrate to ourselves, then we know it is an option that can work.
    1. See other TSTool command code such as RunProgram - can copy and paste code for this. This involves setting up a tabbed pane and then adding parameters to each pane.
    2. One tab can be labeled "Message" and have everything that is there now.
    3. Other tabs can be defined for the other parameters. Without knowing what is needed, I can't provide definitive recommendations but something like "Mail Program", or even individual "Windows Mail", "sendmail", etc. could be used. Take a cut and we can clean up. The point is to group parameters under appropriate tabs and use default values so they have to change as little as possible.
    4. I'm assuming separate tabs for each mail proram below.
  3. Add a command parameter MailProgram as a choice with possible values JavaAPI, Sendmail, WindowsMail.
    1. A blank will default to whatever is the least difficult to set up for the platform or possibly JavaAPI since built in.
    2. This will indicate what the specific parameters are used.
  4. Add parameters and tab "JavaAPI" for Java API.
    1. Note at the top of the tabbed pane will explain that an SMTP server is needed with account through which to send the email.
    2. SMTPServer: Such as Google SMTP server address.
    3. SMTPAccount or SMTPLogin. If this is needed for the other email programs then maybe add a separate tab "SMTP".
    4. SMTPPassword. I need to see Markdown documentation ASAP explaining this.
    5. As for .mailpass file, the documentation needs to be very clear that it is plain text and relies on the user's account being known only to the user. If Linux, the software can check for file mode 600 but I can add that later when I test on Linux. I suggest defaulting the file to a more standard Windows user folder such as under %APPDATA%\tstool\.smtp.cfg to take advantage of the security of that folder. On Linux, maybe use $HOME/.tstool/NN/system/.smtp.cfg.
    6. Maybe also support environment variable and prompt like the ReclamationHDB data store.
  5. Add parameters and tab "Windows Mail" for Windows email:
    1. Add note at the top of the tabbed pane summarizing how it works. The documentation provides the details. It is OK to say it is not yet implemented.
    2. If it is implemented, see RunR command for how to run a program. This can get complicated so take a cut and I can review.
  6. Add parameters and tab "sendmail" for sendmail.
    1. Add note at the top of the tabbed pane summarizing how it works: the sendmail program will be called with command line necessary to send the email. Is any software setup needed? It is OK to say that it is not yet implemented.
    2. Are any additional parameters needed?
    3. If it is implemented, see RunR command for how to run a program. Take a cut and I can review.
  7. Checks for checkParameters method:
    1. Can only specify Message or MessageFile, not both.
    2. Make sure that required parameters are specified for the program being used.