protected DCServerFactory.ResultCode sendEmail(
     String frEmail, String toEmail, String subj, String body) {
   if (StringTools.isBlank(frEmail)) {
     Print.logError("'From' Email address not specified");
     return DCServerFactory.ResultCode.TRANSMIT_FAIL;
   } else if (StringTools.isBlank(toEmail) || !CommandPacketHandler.validateAddress(toEmail)) {
     Print.logError("'To' SMS Email address invalid, or not specified");
     return DCServerFactory.ResultCode.TRANSMIT_FAIL;
   } else if (StringTools.isBlank(subj) && StringTools.isBlank(body)) {
     Print.logError("Command string not specified");
     return DCServerFactory.ResultCode.INVALID_ARG;
   } else {
     try {
       Print.logInfo("SMS email: to <" + toEmail + ">");
       Print.logDebug("  From   : " + frEmail);
       Print.logDebug("  To     : " + toEmail);
       Print.logDebug("  Subject: " + subj);
       Print.logDebug("  Message: " + body);
       SendMail.send(frEmail, toEmail, null, null, subj, body, null);
       return DCServerFactory.ResultCode.SUCCESS;
     } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
       // this will fail if JavaMail support for SendMail is not available.
       Print.logWarn("SendMail error: " + t);
       return DCServerFactory.ResultCode.TRANSMIT_FAIL;
     }
   }
 }
Exemple #2
0
 /* validate the syntax of the specified list of multiple email addresses */
 public static boolean validateAddresses(String addrs, boolean acceptSMS) {
   if (StringTools.isBlank(addrs)) {
     // blank is ok in this case
     return true;
   } else if (acceptSMS) {
     // allow "sms:123456789" format
     String addrArry[] = StringTools.parseStringArray(addrs, ',');
     if (addrArry.length == 0) {
       return false;
     }
     for (int i = 0; i < addrArry.length; i++) {
       String em = addrArry[i].trim();
       if (StringTools.isBlank(em)) {
         // individual addresses not allowed
         return false;
       } else if (SMSOutboundGateway.StartsWithSMS(em)) {
         // TODO: for now, accept as-is
       } else if (!validateAddress(em)) {
         return false;
       }
     }
     return true;
   } else {
     // true email addresses only
     try {
       return SendMail.validateAddresses(addrs);
     } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
       // this will fail if JavaMail support for SendMail is not available.
       Print.logError("*** SendMail error: " + t);
       return false;
     }
   }
 }
Exemple #3
0
 private String getEmail() {
   RTProperties rtp = this.getProperties();
   String email = rtp.getString(PROP_email, null);
   if (StringTools.isBlank(email)) {
     email = SendMail.getUserFromEmailAddress();
   }
   return email;
 }
Exemple #4
0
 /* extract email address from the specified string */
 public static String getEMailAddress(String addr) {
   // extract/normalize email address
   try {
     return SendMail.getEMailAddress(addr);
   } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
     // this will fail if JavaMail support for SendMail is not available.
     Print.logWarn("SendMail error: " + t);
     return null;
   }
 }
Exemple #5
0
 /* validate the syntax of the specified single email address */
 public static boolean validateAddress(String addr) {
   if (StringTools.isBlank(addr)) {
     // blanks not alowed here
     return false; // fail quickly
   } else {
     try {
       return SendMail.validateAddress(addr);
     } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
       // this will fail if JavaMail support for SendMail is not available.
       Print.logWarn("SendMail error: " + t);
       return false;
     }
   }
 }
Exemple #6
0
 /* send an email  with attachment */
 public static boolean send(
     String from,
     String to,
     String cc,
     String bcc,
     String subject,
     String msgBody,
     SendMail.SmtpProperties smtpProps,
     SendMail.Attachment attach) {
   try {
     return SendMail.send(from, to, cc, bcc, subject, msgBody, attach, smtpProps);
   } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException
     // this will fail if JavaMail support for SendMail is not available.
     Print.logWarn("SendMail error: " + t);
     return false;
   }
 }