public static void sendEmail(State state, String subject, String message) throws EmailException {
    Email email = new SimpleEmail();
    email.setHostName(state.getProp(ConfigurationKeys.EMAIL_HOST_KEY, ConfigurationKeys.DEFAULT_EMAIL_HOST));
    if (state.contains(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)) {
      email.setSmtpPort(state.getPropAsInt(ConfigurationKeys.EMAIL_SMTP_PORT_KEY));
    }
    email.setFrom(state.getProp(ConfigurationKeys.EMAIL_FROM_KEY));
    if (state.contains(ConfigurationKeys.EMAIL_USER_KEY) && state.contains(ConfigurationKeys.EMAIL_PASSWORD_KEY)) {
      email.setAuthentication(state.getProp(ConfigurationKeys.EMAIL_USER_KEY),
          PasswordManager.getInstance(state).readPassword(state.getProp(ConfigurationKeys.EMAIL_PASSWORD_KEY)));
    }
    Iterable<String> tos =
        Splitter.on(',').trimResults().omitEmptyStrings().split(state.getProp(ConfigurationKeys.EMAIL_TOS_KEY));
    for (String to : tos) {
      email.addTo(to);
    }

    String hostName;
    try {
      hostName = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException uhe) {
      LOGGER.error("Failed to get the host name", uhe);
      hostName = "unknown";
    }

    email.setSubject(subject);
    String fromHostLine = String.format("This email was sent from host: %s%n%n", hostName);
    email.setMsg(fromHostLine + message);
    email.send();
  }
public static void sendEmail ( State state , String subject , String message ) throws EmailException { Email email = new SimpleEmail ( ) ; email . setHostName ( state . getProp ( ConfigurationKeys . EMAIL_HOST_KEY , ConfigurationKeys . DEFAULT_EMAIL_HOST ) ) ; if ( state . contains ( ConfigurationKeys . EMAIL_SMTP_PORT_KEY ) ) { email . setSmtpPort ( state . getPropAsInt ( ConfigurationKeys . EMAIL_SMTP_PORT_KEY ) ) ; } email . setFrom ( state . getProp ( ConfigurationKeys . EMAIL_FROM_KEY ) ) ; if ( state . contains ( ConfigurationKeys . EMAIL_USER_KEY ) && state . contains ( ConfigurationKeys . EMAIL_PASSWORD_KEY ) ) { email . setAuthentication ( state . getProp ( ConfigurationKeys . EMAIL_USER_KEY ) , PasswordManager . getInstance ( state ) . readPassword ( state . getProp ( ConfigurationKeys . EMAIL_PASSWORD_KEY ) ) ) ; } Iterable < String > tos = Splitter . on ( ',' ) . trimResults ( ) . omitEmptyStrings ( ) . split ( state . getProp ( ConfigurationKeys . EMAIL_TOS_KEY ) ) ; for ( String to : tos ) { email . addTo ( to ) ; } String hostName ; try { hostName = InetAddress . getLocalHost ( ) . getHostName ( ) ; } catch ( UnknownHostException uhe ) { LOGGER . error ( "Failed to get the host name" , uhe ) ; hostName = "unknown" ; } email . setSubject ( subject ) ; String fromHostLine = String . format ( "This email was sent from host: %s%n%n" , hostName ) ; email . setMsg ( fromHostLine + message ) ; email . send ( ) ; }
A general method for sending emails.

@param state a {@link State} object containing configuration properties
@param subject email subject
@param message email message
@throws EmailException if there is anything wrong sending the email