Example #1
0
  /**
   * Notify the user via mail.
   *
   * @param user User who has to be notified
   * @param message The message to send to the user
   */
  public static final void notifyViaMail(User user, String message) {
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);

    try {
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress(WEBMON_EMAIL, WEBMON_NAME));
      msg.addRecipient(
          Message.RecipientType.TO, new InternetAddress(user.getEmail(), user.getName()));
      msg.setSubject(WEBMON_SUBJECT);
      msg.setText(message);
      Transport.send(msg);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #2
0
  /**
   * Notify the user via SMS.
   *
   * @param user User who has to be notified
   * @param message The message to send to the user
   */
  public static final void notifyViaSms(User user, String message) {
    // Create a Twilio REST client
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
    Account account = client.getAccount();

    // Use the API to send a text message
    SmsFactory smsFactory = account.getSmsFactory();
    Map<String, String> smsParams = new HashMap<String, String>();
    smsParams.put("To", "+1" + user.getPhone());
    smsParams.put("From", TWILIO_NUMBER);
    smsParams.put("Body", message);
    try {
      smsFactory.create(smsParams);
    } catch (TwilioRestException e) {
      e.printStackTrace();
    }
  }