diff --git a/scripts/create-smtp-cfg.sh b/scripts/create-smtp-cfg.sh new file mode 100644 index 00000000..51c96d0d --- /dev/null +++ b/scripts/create-smtp-cfg.sh @@ -0,0 +1,28 @@ +#!/bin/bash +(set -o igncr) 2>/dev/null && set -o igncr; # this comment is required +# The above line ensures that the script can be run on Cygwin/Linux even with Windows CRNL + +# TODO: Change location of script depending on Windows or Linux. Only Windows is handled now. + +# Check command line arguments for the help command, or if 2 commands were not given +if [ $# -eq 1 ] && [ $1 = "--help" ]; then + echo "Help" + exit 0 +elif [ $# -ne 2 ]; then + echo " Usage: ./create-smtp-cfg.sh " + echo " or ./create-smtp-cfg.sh --help for more information" + exit 1 +else + accountID=$1 + accountPassword=$2 +fi + +# +mailPassFile=${APPDATA}/tstool/.smtp.cfg +if [ ! -f ${mailPassFile} ]; then + touch ${mailPassFile} + chmod 600 ${mailPassFile} +fi + +# Write the user ID and password to the file. Overwrite each time. +echo ${accountID}:${accountPassword} > ${mailPassFile} diff --git a/src/rti/tscommandprocessor/commands/email/SendEmailMessage_Command.java b/src/rti/tscommandprocessor/commands/email/SendEmailMessage_Command.java index 40f5b698..0ccad322 100644 --- a/src/rti/tscommandprocessor/commands/email/SendEmailMessage_Command.java +++ b/src/rti/tscommandprocessor/commands/email/SendEmailMessage_Command.java @@ -24,17 +24,27 @@ package rti.tscommandprocessor.commands.email; import java.io.File; +import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Properties; +import java.util.Scanner; +import javax.activation.DataHandler; +import javax.activation.DataSource; +import javax.activation.FileDataSource; +import javax.mail.BodyPart; import javax.mail.MessagingException; +import javax.mail.Multipart; +import javax.mail.internet.MimeBodyPart; +import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; import javax.swing.JFrame; import rti.tscommandprocessor.core.TSCommandProcessorUtil; @@ -53,6 +63,7 @@ import RTi.Util.Message.Message; import RTi.Util.Message.MessageUtil; + /** This class initializes, checks, and runs the SendEmailMessage() command. */ @@ -65,6 +76,11 @@ public class SendEmailMessage_Command extends AbstractCommand implements Command protected final String _Ignore = "Ignore"; protected final String _Warn = "Warn"; protected final String _Fail = "Fail"; +protected final String _JavaAPI = "JavaAPI"; +protected final String _Sendmail = "Sendmail"; +protected final String _WindowsMail = "WindowsMail"; + +protected String _SMTPConfigPath = System.getenv("APPDATA") + "\\tstool\\.smtp.cfg"; /** Constructor. @@ -83,11 +99,15 @@ public SendEmailMessage_Command () */ public void checkCommandParameters ( PropList parameters, String command_tag, int warning_level ) throws InvalidCommandParameterException -{ String To = parameters.getValue ( "To" ); +{ String MailProgram = parameters.getValue("MailProgram"); + String To = parameters.getValue ( "To" ); String Subject = parameters.getValue ( "Subject" ); - //String Message0 = parameters.getValue ( "Message" ); - //String MessageFile = parameters.getValue ( "MessageFile" ); + String Message0 = parameters.getValue ( "Message" ); + String MessageFile = parameters.getValue ( "MessageFile" ); String IfNotFound = parameters.getValue ( "IfNotFound" ); + String SMTPServer = parameters.getValue ( "SMTPServer" ); + String SMTPAccount = parameters.getValue ( "SMTPAccount" ); + String SMTPPassword = parameters.getValue ( "SMTPPassword" ); String warning = ""; String message; @@ -96,7 +116,7 @@ public void checkCommandParameters ( PropList parameters, String command_tag, in // The existence of the file to append is not checked during initialization // because files may be created dynamically at runtime. - + // If the To field is not given, warn the user. if ( (To == null) || To.isEmpty() ) { message = "The \"To\" addresses must be specified."; warning += "\n" + message; @@ -104,6 +124,7 @@ public void checkCommandParameters ( PropList parameters, String command_tag, in new CommandLogRecord(CommandStatusType.FAILURE, message, "Specify the To addresses.")); } + // If the Subject is not given, warn the user. if ( (Subject == null) || Subject.isEmpty() ) { message = "The subject must be specified."; warning += "\n" + message; @@ -122,8 +143,44 @@ public void checkCommandParameters ( PropList parameters, String command_tag, in _Fail + ".")); } } + // If neither a message or message file is given, warn the user. + if ( (Message0 == null) && (MessageFile == null)) { + message = "The Message or Message file must be specified."; + warning += "\n" + message; + status.addToLog(CommandPhaseType.INITIALIZATION, + new CommandLogRecord(CommandStatusType.FAILURE, + message, "Specify the message or message file.")); + } + // If both a message and message file + if ( ((Message0 != null) && (MessageFile != null)) ) { + message = "The Message and Message file cannot both be specified."; + warning += "\n" + message; + status.addToLog(CommandPhaseType.INITIALIZATION, + new CommandLogRecord(CommandStatusType.FAILURE, + message, "Specify either the message or message file.")); + } + // JavaAPI (default) chosen and one of the SMTP text fields is empty + if ( (MailProgram == null) || (MailProgram.equals(_JavaAPI)) ) { + if (!SMTPPassword.equalsIgnoreCase("smtp.cfg")) { + // Don't do anything, don't need to check if all three fields are null. ONLY if the password is smtp.cfg. + message = "SMTPPassword must be smtp.cfg."; + warning += "\n" + message; + status.addToLog(CommandPhaseType.INITIALIZATION, + new CommandLogRecord(CommandStatusType.FAILURE, + message, "SMTPPassword must be smtp.cfg.")); + } +// else if ( (SMTPServer == null) || (SMTPAccount == null) || (SMTPPassword == null) ) { +// message = "All SMTP fields must be filled out when using JavaAPI"; +// warning += "\n" + message; +// status.addToLog(CommandPhaseType.INITIALIZATION, +// new CommandLogRecord(CommandStatusType.FAILURE, +// message, "Specify either the message or message file.")); +// } + + } // Check for invalid parameters... - List validList = new ArrayList(9); + List validList = new ArrayList(13); + validList.add ( "MailProgram" ); validList.add ( "From" ); validList.add ( "To" ); validList.add ( "CC" ); @@ -133,6 +190,9 @@ public void checkCommandParameters ( PropList parameters, String command_tag, in validList.add ( "MessageFile" ); validList.add ( "AttachmentFiles" ); validList.add ( "IfNotFound" ); + validList.add( "SMTPServer" ); + validList.add( "SMTPAccount" ); + validList.add( "SMTPPassword" ); warning = TSCommandProcessorUtil.validateParameterNames ( validList, this, warning ); if ( warning.length() > 0 ) { @@ -185,77 +245,96 @@ public void runCommand ( int command_number ) status.clearLog(commandPhase); } + String MailProgram = parameters.getValue( "MailProgram" ); + if ( (MailProgram == null) || (MailProgram.equals("")) ) { + MailProgram = _JavaAPI; // Default + } String From = parameters.getValue ( "From" ); String To = parameters.getValue ( "To" ); String CC = parameters.getValue ( "CC" ); String BCC = parameters.getValue ( "BCC" ); String Subject = parameters.getValue ( "Subject" ); String Message0 = parameters.getValue ( "Message" ); - //String MessageFile = parameters.getValue ( "MessageFile" ); +// String MessageFile = parameters.getValue ( "MessageFile" ); String AttachmentFiles = parameters.getValue ( "AttachmentFiles" ); String IfNotFound = parameters.getValue ( "IfNotFound" ); if ( (IfNotFound == null) || IfNotFound.equals("")) { IfNotFound = _Warn; // Default } - + String[] SMTPParameters = new String[3]; + if (MailProgram.equals(_JavaAPI)) { + SMTPParameters[0] = parameters.getValue("SMTPServer"); +// SMTPParameters[1] = parameters.getValue("SMTPAccount"); + SMTPParameters[2] = parameters.getValue("SMTPPassword"); + +// System.out.println(IOUtil.verifyPathForOS(_SMTPConfigPath)); + } + //String MessageFile_full = IOUtil.verifyPathForOS( // IOUtil.toAbsolutePath(TSCommandProcessorUtil.getWorkingDir(processor), // TSCommandProcessorUtil.expandParameterValue(processor,this,MessageFile) ) ); - String AttachmentFiles_full = IOUtil.verifyPathForOS( - IOUtil.toAbsolutePath(TSCommandProcessorUtil.getWorkingDir(processor), - TSCommandProcessorUtil.expandParameterValue(processor,this,AttachmentFiles) ) ); - // Expand to a list of files... - File f = new File(AttachmentFiles_full); - String ext = null; - List fileList = new ArrayList(); - if ( AttachmentFiles_full.indexOf("*") < 0 ) { - // Processing a single file - fileList.add(new File(AttachmentFiles_full)); - } - else if ( f.getName().equals("*") ) { - // Process all files in folder - fileList = Arrays.asList(f.getParentFile().listFiles()); - } - else if ( f.getName().startsWith("*.") ) { - // Process all files in the folder with the matching extension - ext = IOUtil.getFileExtension(f.getName()); - // TODO SAM 2016-02-08 Need to enable parameter for case - fileList = IOUtil.getFilesMatchingPattern(f.getParent(),ext,false); - } - if ( fileList.size() == 0 ) { - message = "Unable to match any files using AttachmentFiles=\"" + AttachmentFiles + "\""; - if ( IfNotFound.equalsIgnoreCase(_Fail) ) { - Message.printWarning ( warning_level, - MessageUtil.formatMessageTag(command_tag,++warning_count), routine, message ); - status.addToLog(CommandPhaseType.RUN, new CommandLogRecord(CommandStatusType.FAILURE, - message, "Verify that the input file(s) exist(s) at the time the command is run.")); - } - else if ( IfNotFound.equalsIgnoreCase(_Warn) ) { - Message.printWarning ( warning_level, - MessageUtil.formatMessageTag(command_tag,++warning_count), routine, message ); - status.addToLog(CommandPhaseType.RUN, new CommandLogRecord(CommandStatusType.WARNING, - message, "Verify that the input file(s) exist(s) at the time the command is run.")); - } - } - for ( File file : fileList ) { - if ( !file.exists() ) { - message = "Attachment file \"" + file + "\" does not exist."; - if ( IfNotFound.equalsIgnoreCase(_Fail) ) { - Message.printWarning ( warning_level, - MessageUtil.formatMessageTag(command_tag,++warning_count), routine, message ); - status.addToLog(CommandPhaseType.RUN, new CommandLogRecord(CommandStatusType.FAILURE, - message, "Verify that the attachment file exists at the time the command is run.")); - } - else if ( IfNotFound.equalsIgnoreCase(_Warn) ) { - Message.printWarning ( warning_level, - MessageUtil.formatMessageTag(command_tag,++warning_count), routine, message ); - status.addToLog(CommandPhaseType.RUN, new CommandLogRecord(CommandStatusType.WARNING, - message, "Verify that the attachment file exists at the time the command is run.")); - } - else { - Message.printStatus( 2, routine, message + " Ignoring."); - } - } + + // Check if AttachmentFiles is null. If not, then process. + List fileList = null; + + if (AttachmentFiles != null) { + String AttachmentFiles_full = IOUtil.verifyPathForOS( + IOUtil.toAbsolutePath(TSCommandProcessorUtil.getWorkingDir(processor), + TSCommandProcessorUtil.expandParameterValue(processor,this,AttachmentFiles) ) ); + // Expand to a list of files... + File f = new File(AttachmentFiles_full); + String ext = null; + fileList = new ArrayList(); + if ( AttachmentFiles_full.indexOf("*") < 0 ) { + // Processing a single file + fileList.add(new File(AttachmentFiles_full)); + } + else if ( f.getName().equals("*") ) { + // Process all files in folder + fileList = Arrays.asList(f.getParentFile().listFiles()); + } + else if ( f.getName().startsWith("*.") ) { + // Process all files in the folder with the matching extension + ext = IOUtil.getFileExtension(f.getName()); + // TODO SAM 2016-02-08 Need to enable parameter for case + fileList = IOUtil.getFilesMatchingPattern(f.getParent(),ext,false); + } + if ( fileList.size() == 0 ) { + message = "Unable to match any files using AttachmentFiles=\"" + AttachmentFiles + "\""; + if ( IfNotFound.equalsIgnoreCase(_Fail) ) { + Message.printWarning ( warning_level, + MessageUtil.formatMessageTag(command_tag,++warning_count), routine, message ); + status.addToLog(CommandPhaseType.RUN, new CommandLogRecord(CommandStatusType.FAILURE, + message, "Verify that the input file(s) exist(s) at the time the command is run.")); + } + else if ( IfNotFound.equalsIgnoreCase(_Warn) ) { + Message.printWarning ( warning_level, + MessageUtil.formatMessageTag(command_tag,++warning_count), routine, message ); + status.addToLog(CommandPhaseType.RUN, new CommandLogRecord(CommandStatusType.WARNING, + message, "Verify that the input file(s) exist(s) at the time the command is run.")); + } + } + // Print warnings depending on what was picked from the drop-down list. + for ( File file : fileList ) { + if ( !file.exists() ) { + message = "Attachment file \"" + file + "\" does not exist."; + if ( IfNotFound.equalsIgnoreCase(_Fail) ) { + Message.printWarning ( warning_level, + MessageUtil.formatMessageTag(command_tag,++warning_count), routine, message ); + status.addToLog(CommandPhaseType.RUN, new CommandLogRecord(CommandStatusType.FAILURE, + message, "Verify that the attachment file exists at the time the command is run.")); + } + else if ( IfNotFound.equalsIgnoreCase(_Warn) ) { + Message.printWarning ( warning_level, + MessageUtil.formatMessageTag(command_tag,++warning_count), routine, message ); + status.addToLog(CommandPhaseType.RUN, new CommandLogRecord(CommandStatusType.WARNING, + message, "Verify that the attachment file exists at the time the command is run.")); + } + else { + Message.printStatus( 2, routine, message + " Ignoring."); + } + } + } } if ( warning_count > 0 ) { message = "There were " + warning_count + " warnings about command parameters."; @@ -284,7 +363,16 @@ else if ( IfNotFound.equalsIgnoreCase(_Warn) ) { */ try { - sendEmailMessage ( To, From, CC, BCC, Subject, Message0 ); + if (MailProgram.equals(_JavaAPI)) { + sendEmailMessageViaJavaAPI ( To, From, CC, BCC, Subject, Message0, MailProgram, fileList, SMTPParameters ); + } + else if (MailProgram.equals(_Sendmail)) { + sendEmailMessageViaSendmail(); + } + else if (MailProgram.equals(_WindowsMail)) { + sendEmailMessageViaWindowsMail(); + } + } catch ( Exception e ) { Message.printWarning ( 3, routine, e ); @@ -319,19 +407,84 @@ else if ( IfNotFound.equalsIgnoreCase(_Warn) ) { * @param subject * @param message */ -private MimeMessage createEmailMessage ( Session session, String from, String to, String cc, String bcc, String subject, String message ) +private MimeMessage createEmailMessage ( Session session, String from, String to, String cc, String bcc, String subject, + String message, List fileList ) throws AddressException, MessagingException { MimeMessage emailMessage = new MimeMessage(session); InternetAddress toAddress = new InternetAddress(to); InternetAddress fromAddress = new InternetAddress(from); + emailMessage.setFrom(fromAddress); emailMessage.addRecipient(javax.mail.Message.RecipientType.TO, toAddress); emailMessage.setSubject(subject); - emailMessage.setText(message); + + // If any attachment files are present, send them along with the message + if (fileList != null) { + + Multipart multipart = new MimeMultipart(); + BodyPart messageBodyPart = new MimeBodyPart(); + messageBodyPart.setText(message); + // Iterate over each attachment file and add them to the multipart object + for (File file: fileList) { + BodyPart attachmentBodyPart = new MimeBodyPart(); + + DataSource source = new FileDataSource(file); + attachmentBodyPart.setDataHandler(new DataHandler(source)); + // If forward or backward slash. + if (file.toString().lastIndexOf("\\") != -1) { + attachmentBodyPart.setFileName(file.toString().substring(file.toString().lastIndexOf("\\") + 1)); + } else { + attachmentBodyPart.setFileName(file.toString().substring(file.toString().lastIndexOf("/") + 1)); + } + // Add the attached file to the Multipart. + multipart.addBodyPart(attachmentBodyPart); + } + // Add the message body part to the Multipart + multipart.addBodyPart(messageBodyPart); + // Set the message body part and subsequent attachment body parts to the MimeMessage emailMessage. + emailMessage.setContent(multipart); + } else { + emailMessage.setText(message); + } + + // Add any CC users to recipients. + if (cc != null) { + for (String ccRecipient: cc.split(",")) { + emailMessage.addRecipient(javax.mail.Message.RecipientType.CC, new InternetAddress(ccRecipient)); + } + } + // Add any BCC users to recipients. + if (bcc != null) { + for (String bccRecipient: bcc.split(",")) { + emailMessage.addRecipient(javax.mail.Message.RecipientType.BCC, new InternetAddress(bccRecipient)); + } + } + return emailMessage; } +/** + * Reads in the contents of the .mailpass file in the user's home directory with the correct email user name and + * password. To be used as the user's credentials when trying to send an email. + * @return An array of length two containing the user's email ID and password. + */ +private String[] readUserCredentials() throws FileNotFoundException { + + String fullSMTPConfigPath = IOUtil.verifyPathForOS(System.getenv("APPDATA") + "\\tstool\\.smtp.cfg"); + String[] credentials = new String[2]; + + File myObj = new File(fullSMTPConfigPath); + Scanner myReader = new Scanner(myObj); + while (myReader.hasNextLine()) { + String data = myReader.nextLine(); + credentials = data.split(":"); + } + myReader.close(); + + return credentials; +} + /** * Send an email message. * @param to @@ -340,22 +493,59 @@ private MimeMessage createEmailMessage ( Session session, String from, String to * @param bcc * @param subject * @param message + * @param MailProgram + * @param fileList + * @param SMTPParameters * @throws AddressException * @throws MessagingException + * @throws FileNotFoundException */ -private void sendEmailMessage ( String to, String from, String cc, String bcc, String subject, String message ) -throws AddressException, MessagingException { +private void sendEmailMessageViaJavaAPI ( String to, String from, String cc, String bcc, String subject, String message, + String MailProgram, List fileList, String[] SMTPParameters ) +throws AddressException, MessagingException, FileNotFoundException { + Properties props = new Properties(); - // TODO SAM 2016-04-02 Need to set properties for email server here - // See: http://crunchify.com/java-mailapi-example-send-an-email-via-gmail-smtp/ - Session session = Session.getDefaultInstance(props,null); - MimeMessage emailMessage = createEmailMessage ( session, from, to, cc, bcc, subject, message ); - Transport transport = session.getTransport("smtp"); - String accountId = ""; - String accountPassword = ""; - transport.connect("smtp.gmail.com",accountId,accountPassword); - transport.sendMessage(emailMessage,emailMessage.getAllRecipients()); - transport.close(); + // Port 25 is the default port used, and is considered to not be a great option, as many firewalls will block + // it. The following 2 ports are suggested, in order of importance. Port 587 - Uses STARTTLS. Port 465- Uses SMTPS + // Set properties. See: http://crunchify.com/java-mailapi-example-send-an-email-via-gmail-smtp/ + props.put("mail.smtp.port", "587"); + props.put("mail.smtp.auth", "true"); + props.put("mail.smtp.starttls.enable", "true"); + + // Password can only be smtp.cfg to read from the smtp.cfg file. + if (SMTPParameters[2].equalsIgnoreCase("smtp.cfg")) { + // Populate the 2 element sized array userCredentials with accountID and accountPassword + String[] userCredentials = readUserCredentials(); + String accountId = userCredentials[0]; + // This is recommended to be an app-specific password for Google. + String accountPassword = userCredentials[1]; + Session session = Session.getInstance(props, new javax.mail.Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(accountId, accountPassword); + } + }); + + MimeMessage emailMessage = createEmailMessage ( session, from, to, cc, bcc, subject, message, fileList ); + Transport transport = session.getTransport("smtp"); + // Use the smtp server provided from the SMTP Server text field. + transport.connect(SMTPParameters[0],accountId,accountPassword); + transport.sendMessage(emailMessage,emailMessage.getAllRecipients()); + transport.close(); + } + + + +} + +/** + * + */ +private void sendEmailMessageViaSendmail() { + +} + +private void sendEmailMessageViaWindowsMail() { + } /** @@ -365,6 +555,7 @@ public String toString ( PropList parameters ) { if ( parameters == null ) { return getCommandName() + "()"; } + String MailProgram = parameters.getValue("MailProgram"); String From = parameters.getValue("From"); String To = parameters.getValue("To"); String CC = parameters.getValue("CC"); @@ -374,8 +565,18 @@ public String toString ( PropList parameters ) String MessageFile = parameters.getValue("MessageFile"); String AttachmentFiles = parameters.getValue("AttachmentFiles"); String IfNotFound = parameters.getValue("IfNotFound"); + String SMTPServer = parameters.getValue("SMTPServer"); + String SMTPAccount = parameters.getValue("SMTPAccount"); + String SMTPPassword = parameters.getValue("SMTPPassword"); StringBuffer b = new StringBuffer (); + + if ( (MailProgram != null) && (MailProgram.length() > 0) ) { + b.append ( "MailProgram=" + MailProgram ); + } if ( (From != null) && (From.length() > 0) ) { + if ( b.length() > 0 ) { + b.append ( "," ); + } b.append ( "From=\"" + From + "\"" ); } if ( (To != null) && (To.length() > 0) ) { @@ -426,6 +627,24 @@ public String toString ( PropList parameters ) } b.append ( "IfNotFound=" + IfNotFound ); } + if ( (SMTPServer != null) && (SMTPServer.length() > 0) ) { + if ( b.length() > 0 ) { + b.append ( "," ); + } + b.append ( "SMTPServer=\"" + SMTPServer + "\"" ); + } + if ( (SMTPAccount != null) && (SMTPAccount.length() > 0) ) { + if ( b.length() > 0 ) { + b.append ( "," ); + } + b.append ( "SMTPAccount=\"" + SMTPAccount + "\"" ); + } + if ( (SMTPPassword != null) && (SMTPPassword.length() > 0) ) { + if ( b.length() > 0 ) { + b.append ( "," ); + } + b.append ( "SMTPPassword=\"" + SMTPPassword + "\"" ); + } return getCommandName() + "(" + b.toString() + ")"; } diff --git a/src/rti/tscommandprocessor/commands/email/SendEmailMessage_JDialog.java b/src/rti/tscommandprocessor/commands/email/SendEmailMessage_JDialog.java index 0007162c..a53e064a 100644 --- a/src/rti/tscommandprocessor/commands/email/SendEmailMessage_JDialog.java +++ b/src/rti/tscommandprocessor/commands/email/SendEmailMessage_JDialog.java @@ -44,6 +44,7 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSeparator; +import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingConstants; @@ -73,10 +74,15 @@ public class SendEmailMessage_JDialog extends JDialog private SimpleJButton __help_JButton = null; private SimpleJButton __cancel_JButton = null; private SimpleJButton __ok_JButton = null; +private JTabbedPane __main_JTabbedPane = null; +private SimpleJComboBox __MailProgram_JComboBox = null; private JTextField __From_JTextField = null; private JTextField __To_JTextField = null; private JTextField __CC_JTextField = null; private JTextField __BCC_JTextField = null; +private JTextField __SMTPServer_JTextField = null; +private JTextField __SMTPAccount_JTextField = null; +private JTextField __SMTPPassword_JTextField = null; private JTextField __Subject_JTextField = null; private JTextArea __Message_JTextArea = null; private JTextField __MessageFile_JTextField = null; @@ -229,6 +235,7 @@ to true. This should be called before response() is allowed to complete. private void checkInput () { // Put together a list of parameters to check... PropList props = new PropList ( "" ); + String MailProgram = __MailProgram_JComboBox.getSelected(); String To = __To_JTextField.getText().trim(); String CC = __CC_JTextField.getText().trim(); String BCC = __BCC_JTextField.getText().trim(); @@ -237,6 +244,9 @@ private void checkInput () String MessageFile = __MessageFile_JTextField.getText().trim(); String AttachmentFiles = __AttachmentFiles_JTextField.getText().trim(); String IfNotFound = __IfNotFound_JComboBox.getSelected(); + String SMTPServer = __SMTPServer_JTextField.getText().trim(); + String SMTPAccount = __SMTPAccount_JTextField.getText().trim(); + String SMTPPassword = __SMTPPassword_JTextField.getText().trim(); __error_wait = false; if ( To.length() > 0 ) { props.set ( "To", To ); @@ -262,6 +272,18 @@ private void checkInput () if ( IfNotFound.length() > 0 ) { props.set ( "IfNotFound", IfNotFound ); } + if ( SMTPServer.length() > 0 ) { + props.set( "SMTPServer", SMTPServer ); + } + if ( MailProgram.length() > 0 ) { + props.set( "MailProgram", MailProgram ); + } + if ( SMTPAccount.length() > 0 ) { + props.set( "SMTPAccount", SMTPAccount ); + } + if ( SMTPPassword.length() > 0 ) { + props.set( "SMTPPassword", SMTPPassword ); + } try { // This will warn the user... __command.checkCommandParameters ( props, null, 1 ); } @@ -276,7 +298,8 @@ private void checkInput () already been checked and no errors were detected. */ private void commitEdits () -{ String From = __From_JTextField.getText().trim(); +{ String MailProgram = __MailProgram_JComboBox.getSelected(); + String From = __From_JTextField.getText().trim(); String To = __To_JTextField.getText().trim(); String CC = __CC_JTextField.getText().trim(); String BCC = __BCC_JTextField.getText().trim(); @@ -285,6 +308,10 @@ private void commitEdits () String MessageFile = __MessageFile_JTextField.getText().trim(); String AttachmentFiles = __AttachmentFiles_JTextField.getText().trim(); String IfNotFound = __IfNotFound_JComboBox.getSelected(); + String SMTPServer = __SMTPServer_JTextField.getText().trim(); + String SMTPAccount = __SMTPAccount_JTextField.getText().trim(); + String SMTPPassword = __SMTPPassword_JTextField.getText().trim(); + __command.setCommandParameter ( "MailProgram", MailProgram ); __command.setCommandParameter ( "From", From ); __command.setCommandParameter ( "To", To ); __command.setCommandParameter ( "CC", CC ); @@ -294,6 +321,9 @@ private void commitEdits () __command.setCommandParameter ( "MessageFile", MessageFile ); __command.setCommandParameter ( "AttachmentFiles", AttachmentFiles ); __command.setCommandParameter ( "IfNotFound", IfNotFound ); + __command.setCommandParameter ( "SMTPServer", SMTPServer ); + __command.setCommandParameter ( "SMTPAccount", SMTPAccount ); + __command.setCommandParameter ( "SMTPPassword", SMTPPassword ); } /** @@ -338,76 +368,103 @@ private void initialize ( JFrame parent, SendEmailMessage_Command command ) JGUIUtil.addComponent(main_JPanel, new JSeparator(SwingConstants.HORIZONTAL), 0, ++y, 8, 1, 0, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel ( "From:"), - 0, ++y, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + __main_JTabbedPane = new JTabbedPane (); + JGUIUtil.addComponent(main_JPanel, __main_JTabbedPane, + 0, ++y, 7, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + + // Panel for Message + int yMessage = -1; + JPanel message_JPanel = new JPanel(); + message_JPanel.setLayout( new GridBagLayout() ); + __main_JTabbedPane.addTab ( "Message", message_JPanel ); + + JGUIUtil.addComponent(message_JPanel, new JLabel ( "Mail Program:"), + 0, ++yMessage, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + __MailProgram_JComboBox = new SimpleJComboBox ( false ); + List mailProgramChoices = new ArrayList(); + mailProgramChoices.add ( "" ); // Default + mailProgramChoices.add ( __command._JavaAPI ); + mailProgramChoices.add ( __command._Sendmail ); + mailProgramChoices.add ( __command._WindowsMail ); + __MailProgram_JComboBox.setData(mailProgramChoices); + __MailProgram_JComboBox.select ( 0 ); + __MailProgram_JComboBox.addActionListener ( this ); + JGUIUtil.addComponent(message_JPanel, __MailProgram_JComboBox, + 1, yMessage, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + JGUIUtil.addComponent(message_JPanel, new JLabel( + "Required - method for sending the email message (default=" + __command._JavaAPI + ")"), + 3, yMessage, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + + JGUIUtil.addComponent(message_JPanel, new JLabel ( "From:"), + 0, ++yMessage, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); __From_JTextField = new JTextField ( 40 ); __From_JTextField.setToolTipText("Recipient email addresses, separated by commas, can include ${Property}"); __From_JTextField.addKeyListener ( this ); - JGUIUtil.addComponent(main_JPanel, __From_JTextField, - 1, y, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel( + JGUIUtil.addComponent(message_JPanel, __From_JTextField, + 1, yMessage, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(message_JPanel, new JLabel( "Required - from email address"), - 3, y, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + 3, yMessage, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel ( "To:"), - 0, ++y, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + JGUIUtil.addComponent(message_JPanel, new JLabel ( "To:"), + 0, ++yMessage, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); __To_JTextField = new JTextField ( 40 ); __To_JTextField.setToolTipText("Recipient email addresses, separated by commas, can include ${Property}"); __To_JTextField.addKeyListener ( this ); - JGUIUtil.addComponent(main_JPanel, __To_JTextField, - 1, y, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel( + JGUIUtil.addComponent(message_JPanel, __To_JTextField, + 1, yMessage, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(message_JPanel, new JLabel( "Required - recipient email addresses"), - 3, y, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + 3, yMessage, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel ( "CC:"), - 0, ++y, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + JGUIUtil.addComponent(message_JPanel, new JLabel ( "CC:"), + 0, ++yMessage, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); __CC_JTextField = new JTextField ( 40 ); __CC_JTextField.setToolTipText("CC email addresses, separated by commas, can include ${Property}"); __CC_JTextField.addKeyListener ( this ); - JGUIUtil.addComponent(main_JPanel, __CC_JTextField, - 1, y, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel( + JGUIUtil.addComponent(message_JPanel, __CC_JTextField, + 1, yMessage, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(message_JPanel, new JLabel( "Optional - CC email addresses"), - 3, y, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + 3, yMessage, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel ( "BCC:"), - 0, ++y, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + JGUIUtil.addComponent(message_JPanel, new JLabel ( "BCC:"), + 0, ++yMessage, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); __BCC_JTextField = new JTextField ( 40 ); __BCC_JTextField.setToolTipText("CC email addresses, separated by commas, can include ${Property}"); __BCC_JTextField.addKeyListener ( this ); - JGUIUtil.addComponent(main_JPanel, __BCC_JTextField, - 1, y, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel( + JGUIUtil.addComponent(message_JPanel, __BCC_JTextField, + 1, yMessage, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(message_JPanel, new JLabel( "Optional - BCC email addresses"), - 3, y, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + 3, yMessage, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel ( "Subject:"), - 0, ++y, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + JGUIUtil.addComponent(message_JPanel, new JLabel ( "Subject:"), + 0, ++yMessage, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); __Subject_JTextField = new JTextField ( 40 ); __Subject_JTextField.setToolTipText("Subject for email, can include ${Property}"); __Subject_JTextField.addKeyListener ( this ); - JGUIUtil.addComponent(main_JPanel, __Subject_JTextField, - 1, y, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel( + JGUIUtil.addComponent(message_JPanel, __Subject_JTextField, + 1, yMessage, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(message_JPanel, new JLabel( "Required - email subject"), - 3, y, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + 3, yMessage, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel ( "Message:" ), - 0, ++y, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + JGUIUtil.addComponent(message_JPanel, new JLabel ( "Message:" ), + 0, ++yMessage, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); __Message_JTextArea = new JTextArea ( 10, 80 ); __Message_JTextArea.setToolTipText("Email message, can include ${Property}"); __Message_JTextArea.setLineWrap ( true ); __Message_JTextArea.setWrapStyleWord ( true ); __Message_JTextArea.addKeyListener ( this ); - JGUIUtil.addComponent(main_JPanel, new JScrollPane(__Message_JTextArea), - 1, y, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.BOTH, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel( + JGUIUtil.addComponent(message_JPanel, new JScrollPane(__Message_JTextArea), + 1, yMessage, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.BOTH, GridBagConstraints.WEST); + JGUIUtil.addComponent(message_JPanel, new JLabel( "Required - email message"), - 3, y, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + 3, yMessage, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel ("Message file:" ), - 0, ++y, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + JGUIUtil.addComponent(message_JPanel, new JLabel ("Message file:" ), + 0, ++yMessage, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); __MessageFile_JTextField = new JTextField ( 50 ); __MessageFile_JTextField.setToolTipText("Specify the message file or use ${Property} notation"); __MessageFile_JTextField.addKeyListener ( this ); @@ -426,11 +483,11 @@ private void initialize ( JFrame parent, SendEmailMessage_Command command ) JGUIUtil.addComponent(MessageFile_JPanel, __pathMessage_JButton, 2, 0, 1, 1, 0.0, 0.0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); } - JGUIUtil.addComponent(main_JPanel, MessageFile_JPanel, - 1, y, 6, 1, 1.0, 0.0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(message_JPanel, MessageFile_JPanel, + 1, yMessage, 6, 1, 1.0, 0.0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel ("Attachment file(s):" ), - 0, ++y, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + JGUIUtil.addComponent(message_JPanel, new JLabel ("Attachment file(s):" ), + 0, ++yMessage, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); __AttachmentFiles_JTextField = new JTextField ( 50 ); __AttachmentFiles_JTextField.setToolTipText("Specify the attachment file(s) or use ${Property} notation"); __AttachmentFiles_JTextField.addKeyListener ( this ); @@ -449,11 +506,11 @@ private void initialize ( JFrame parent, SendEmailMessage_Command command ) JGUIUtil.addComponent(AttachmentFiles_JPanel, __pathInput_JButton, 2, 0, 1, 1, 0.0, 0.0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); } - JGUIUtil.addComponent(main_JPanel, AttachmentFiles_JPanel, - 1, y, 6, 1, 1.0, 0.0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(message_JPanel, AttachmentFiles_JPanel, + 1, yMessage, 6, 1, 1.0, 0.0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel ( "If not found?:"), - 0, ++y, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + JGUIUtil.addComponent(message_JPanel, new JLabel ( "If not found?:"), + 0, ++yMessage, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); __IfNotFound_JComboBox = new SimpleJComboBox ( false ); List notFoundChoices = new ArrayList(); notFoundChoices.add ( "" ); // Default @@ -463,11 +520,86 @@ private void initialize ( JFrame parent, SendEmailMessage_Command command ) __IfNotFound_JComboBox.setData(notFoundChoices); __IfNotFound_JComboBox.select ( 0 ); __IfNotFound_JComboBox.addActionListener ( this ); - JGUIUtil.addComponent(main_JPanel, __IfNotFound_JComboBox, - 1, y, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); - JGUIUtil.addComponent(main_JPanel, new JLabel( + JGUIUtil.addComponent(message_JPanel, __IfNotFound_JComboBox, + 1, yMessage, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + JGUIUtil.addComponent(message_JPanel, new JLabel( "Optional - action if input file is not found (default=" + __command._Warn + ")"), - 3, y, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + 3, yMessage, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + + // Panel for JavaAPI + int yJavaAPI = -1; + JPanel javaAPI_JPanel = new JPanel(); + javaAPI_JPanel.setLayout( new GridBagLayout() ); + __main_JTabbedPane.addTab ( "JavaAPI", javaAPI_JPanel ); + + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel ( + "The JavaAPI functionality has not yet been fully implemented."), + 0, ++yJavaAPI, 7, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel ( + "An SMTP server is needed along with the account through which to send the email. For example:"), + 0, ++yJavaAPI, 7, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel ( + " smtp.gmail.com - Gmail"), + 0, ++yJavaAPI, 7, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel ( + " smtp.live.com - Outlook"), + 0, ++yJavaAPI, 7, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel ( + " smtp.mail.yahoo.com - Yahoo"), + 0, ++yJavaAPI, 7, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel ( "SMTP Server:" ), + 0, ++yJavaAPI, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + __SMTPServer_JTextField = new JTextField ( "", 40 ); + __SMTPServer_JTextField.setToolTipText("Set the SMTP server to connect to."); + __SMTPServer_JTextField.addKeyListener ( this ); + JGUIUtil.addComponent(javaAPI_JPanel, __SMTPServer_JTextField, + 1, yJavaAPI, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel( + "Required - the SMTP server to connect to"), + 3, yJavaAPI, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel ( "SMTP Account:" ), + 0, ++yJavaAPI, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + __SMTPAccount_JTextField = new JTextField ( "", 40 ); + __SMTPAccount_JTextField.setToolTipText("Set the SMTP account username / ID."); + __SMTPAccount_JTextField.addKeyListener ( this ); + JGUIUtil.addComponent(javaAPI_JPanel, __SMTPAccount_JTextField, + 1, yJavaAPI, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel( + "Required - the SMTP account to connect to the server. Not yet implemented."), + 3, yJavaAPI, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel ( "SMTP Password:" ), + 0, ++yJavaAPI, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); + __SMTPPassword_JTextField = new JTextField ( "", 40 ); + __SMTPPassword_JTextField.setToolTipText("Set the SMTP account password for authentication."); + __SMTPPassword_JTextField.addKeyListener ( this ); + JGUIUtil.addComponent(javaAPI_JPanel, __SMTPPassword_JTextField, + 1, yJavaAPI, 2, 1, 1, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + JGUIUtil.addComponent(javaAPI_JPanel, new JLabel( + "Required - the SMTP password for authentication"), + 3, yJavaAPI, 2, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.WEST); + + // PANEL FOR WINDOWS MAIL + int yWindowsMail = -1; + JPanel windowsMail_JPanel = new JPanel(); + windowsMail_JPanel.setLayout( new GridBagLayout() ); + __main_JTabbedPane.addTab ( "Windows Mail", windowsMail_JPanel ); + + JGUIUtil.addComponent(windowsMail_JPanel, new JLabel ( + "The Windows Mail functionality has not yet been fully implemented."), + 0, ++yWindowsMail, 7, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); + + // Panel for Sendmail + int ySendMail = -1; + JPanel sendMail_JPanel = new JPanel(); + sendMail_JPanel.setLayout( new GridBagLayout() ); + __main_JTabbedPane.addTab ( "Sendmail", sendMail_JPanel ); + + JGUIUtil.addComponent(sendMail_JPanel, new JLabel ( + "The Sendmail functionality has not yet been fully implemented."), + 0, ++ySendMail, 7, 1, 1, 0, insetsTLBR, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); JGUIUtil.addComponent(main_JPanel, new JLabel ( "Command:" ), 0, ++y, 1, 1, 0, 0, insetsTLBR, GridBagConstraints.NONE, GridBagConstraints.EAST); @@ -533,6 +665,7 @@ public boolean ok () */ private void refresh () { String routine = getClass().getSimpleName() + ".refresh"; + String MailProgram = ""; String From = ""; String To = ""; String CC = ""; @@ -542,10 +675,14 @@ private void refresh () String MessageFile = ""; String AttachmentFiles = ""; String IfNotFound = ""; + String SMTPServer = ""; + String SMTPAccount = ""; + String SMTPPassword = ""; PropList parameters = null; if ( __first_time ) { __first_time = false; parameters = __command.getCommandParameters(); + MailProgram = parameters.getValue( "MailProgram" ); From = parameters.getValue ( "From" ); To = parameters.getValue ( "To" ); CC = parameters.getValue ( "CC" ); @@ -555,6 +692,10 @@ private void refresh () MessageFile = parameters.getValue ( "MessageFile" ); AttachmentFiles = parameters.getValue ( "AttachmentFiles" ); IfNotFound = parameters.getValue ( "IfNotFound" ); + SMTPServer = parameters.getValue ( "SMTPServer" ); + SMTPAccount = parameters.getValue ( "SMTPAccount" ); + SMTPPassword = parameters.getValue ( "SMTPPassword" ); + if ( From != null ) { __From_JTextField.setText ( From ); } @@ -579,11 +720,11 @@ private void refresh () if ( AttachmentFiles != null ) { __AttachmentFiles_JTextField.setText ( AttachmentFiles ); } - if ( JGUIUtil.isSimpleJComboBoxItem(__IfNotFound_JComboBox, IfNotFound,JGUIUtil.NONE, null, null ) ) { + if ( JGUIUtil.isSimpleJComboBoxItem(__IfNotFound_JComboBox, IfNotFound, JGUIUtil.NONE, null, null ) ) { __IfNotFound_JComboBox.select ( IfNotFound ); } else { - if ( (IfNotFound == null) || IfNotFound.equals("") ) { + if ( (IfNotFound == null) || IfNotFound.equals("") ) { // New command...select the default... __IfNotFound_JComboBox.select ( 0 ); } @@ -594,9 +735,33 @@ private void refresh () "\". Select a\n value or Cancel." ); } } + if ( JGUIUtil.isSimpleJComboBoxItem(__MailProgram_JComboBox, MailProgram, JGUIUtil.NONE, null, null ) ) { + __MailProgram_JComboBox.select ( MailProgram ); + } + else { + if ( (MailProgram == null) || MailProgram.equals("") ) { + // New command...select the default... + __MailProgram_JComboBox.select ( 0 ); + } + else { // Bad user command... + Message.printWarning ( 1, routine, + "Existing command references an invalid\n"+ + "MailProgram parameter \"" + MailProgram + + "\". Select a\n value or Cancel." ); + } + } + if ( SMTPServer != null ) { + __SMTPServer_JTextField.setText(SMTPServer); + } + if ( SMTPAccount != null ) { + __SMTPAccount_JTextField.setText(SMTPAccount); + } + if ( SMTPPassword != null ) { + __SMTPPassword_JTextField.setText(SMTPPassword); + } } - // Regardless, reset the command from the fields. This is only visible - // information that has not been committed in the command. + // Regardless, reset the command from the fields. This is only visible information that has not been committed in the command. + MailProgram = __MailProgram_JComboBox.getSelected(); From = __From_JTextField.getText().trim(); To = __To_JTextField.getText().trim(); CC = __CC_JTextField.getText().trim(); @@ -606,7 +771,11 @@ private void refresh () MessageFile = __MessageFile_JTextField.getText().trim(); AttachmentFiles = __AttachmentFiles_JTextField.getText().trim(); IfNotFound = __IfNotFound_JComboBox.getSelected(); + SMTPServer = __SMTPServer_JTextField.getText().trim(); + SMTPAccount = __SMTPAccount_JTextField.getText().trim(); + SMTPPassword = __SMTPPassword_JTextField.getText().trim(); PropList props = new PropList ( __command.getCommandName() ); + props.add ( "MailProgram=" + MailProgram ); props.add ( "From=" + From ); props.add ( "To=" + To ); props.add ( "CC=" + CC ); @@ -616,6 +785,9 @@ private void refresh () props.add ( "MessageFile=" + MessageFile ); props.add ( "AttachmentFiles=" + AttachmentFiles ); props.add ( "IfNotFound=" + IfNotFound ); + props.add ( "SMTPServer=" + SMTPServer ); + props.add ( "SMTPAccount=" + SMTPAccount); + props.add ("SMTPPassword=" + SMTPPassword); __command_JTextArea.setText( __command.toString(props) ); // Check the path and determine what the label on the path button should be... if ( __pathMessage_JButton != null ) {