コード例 #1
0
ファイル: Emailer.java プロジェクト: baojie1985/MNTG
  public static void sendEmail(
      InternetAddress from, InternetAddress to, String content, String requester)
      throws MessagingException, UnsupportedEncodingException {

    Properties props = new Properties();

    props.put("mail.transport.protocol", "smtps");
    props.put("mail.smtps.host", SMTP_HOST_NAME);
    props.put("mail.smtps.auth", "true");

    Session mailSession = Session.getDefaultInstance(props);
    mailSession.setDebug(false);
    Transport transport = mailSession.getTransport();

    MimeMessage message = new MimeMessage(mailSession);
    message.setSubject("MN Traffic Generation is used by " + requester);
    message.setContent(content, "text/plain");

    message.addRecipient(Message.RecipientType.TO, to);

    InternetAddress[] replyto = new InternetAddress[1];
    replyto[0] = from;

    message.setFrom(from);
    message.setReplyTo(replyto);
    message.setSender(from);

    transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);

    transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));

    transport.close();
  }
コード例 #2
0
  public static void main(String[] args) throws MessagingException, IOException {
    Properties props = new Properties();
    try (InputStream in = Files.newInputStream(Paths.get("mail", "mail.properties"))) {
      props.load(in);
    }
    List<String> lines = Files.readAllLines(Paths.get(args[0]), Charset.forName("UTF-8"));

    String from = lines.get(0);
    String to = lines.get(1);
    String subject = lines.get(2);

    StringBuilder builder = new StringBuilder();
    for (int i = 3; i < lines.size(); i++) {
      builder.append(lines.get(i));
      builder.append("\n");
    }

    Console console = System.console();
    String password = new String(console.readPassword("Password: "));

    Session mailSession = Session.getDefaultInstance(props);
    // mailSession.setDebug(true);
    MimeMessage message = new MimeMessage(mailSession);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(RecipientType.TO, new InternetAddress(to));
    message.setSubject(subject);
    message.setText(builder.toString());
    Transport tr = mailSession.getTransport();
    try {
      tr.connect(null, password);
      tr.sendMessage(message, message.getAllRecipients());
    } finally {
      tr.close();
    }
  }
コード例 #3
0
ファイル: SoapConnection.java プロジェクト: forcedotcom/wsc
  public XMLizable send(
      String soapAction,
      QName requestElement,
      XMLizable request,
      QName responseElement,
      Class responseType)
      throws ConnectionException {

    long startTime = System.currentTimeMillis();

    try {
      boolean firstTime = true;
      while (true) {
        try {
          Transport transport = newTransport(config);
          OutputStream out = transport.connect(url, soapAction);
          sendRequest(out, request, requestElement);
          InputStream in = transport.getContent();
          XMLizable result;
          result = receive(transport, responseElement, responseType, in);
          return result;
        } catch (SessionTimedOutException se) {
          if (config.getSessionRenewer() == null || !firstTime) {
            throw (ConnectionException) se.getCause();
          } else {
            SessionRenewer.SessionRenewalHeader sessionHeader =
                config.getSessionRenewer().renewSession(config);
            if (sessionHeader != null) {
              addHeader(sessionHeader.name, sessionHeader.headerElement);
            }
          }
        }
        firstTime = false;
      }
    } catch (SocketTimeoutException e) {
      long timeTaken = System.currentTimeMillis() - startTime;
      throw new ConnectionException(
          "Request to "
              + url
              + " timed out. TimeTaken="
              + timeTaken
              + " ConnectionTimeout="
              + config.getConnectionTimeout()
              + " ReadTimeout="
              + config.getReadTimeout(),
          e);

    } catch (IOException e) {
      throw new ConnectionException("Failed to send request to " + url, e);
    }
  }
コード例 #4
0
ファイル: Mailer.java プロジェクト: StephenJMoore/MovieKiosk
  public void mail(String toAddress, String subject, String body) {
    Properties props = new Properties();
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", port);
    props.put("mail.smtp.ssl.enable", true);
    Authenticator authenticator = null;
    if (login) {
      props.put("mail.smtp.auth", true);
      authenticator =
          new Authenticator() {
            private PasswordAuthentication pa = new PasswordAuthentication(username, password);

            @Override
            public PasswordAuthentication getPasswordAuthentication() {
              return pa;
            }
          };
    }

    Session s = Session.getInstance(props, authenticator);
    s.setDebug(debug);
    MimeMessage email = new MimeMessage(s);
    try {
      email.setFrom(new InternetAddress(from));
      email.setRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));
      email.setSubject(subject);
      email.setSentDate(new Date());
      email.setText(body);
      Transport.send(email);
    } catch (MessagingException ex) {
      ex.printStackTrace();
    }
  }
コード例 #5
0
ファイル: AutoMessage.java プロジェクト: k-q-11/java
  public void send() {
    // Your SMTP server address here.
    String smtpHost = "myserver.jeffcorp.com";
    // The sender's email address
    String from = "*****@*****.**";
    // The recepients email address
    String to = "*****@*****.**";

    Properties props = new Properties();
    // The protocol to use is SMTP
    props.put("mail.smtp.host", smtpHost);

    Session session = Session.getDefaultInstance(props, null);

    try {
      InternetAddress[] address = {new InternetAddress(to)};
      MimeMessage message;

      message = new MimeMessage(session);
      message.setFrom(new InternetAddress(from));

      message.setRecipients(Message.RecipientType.TO, to);
      message.setSubject("Hello from Jeff");
      message.setSentDate(sendDate);
      message.setText("Hello Jeff, \nHow are things going?");

      Transport.send(message);

      System.out.println("email has been sent.");
    } catch (Exception e) {
      System.out.println(e);
    }
  }
コード例 #6
0
ファイル: SentMail.java プロジェクト: BuladacoJonard/CTL_USF
  /** Sends Emails to Customers who have not submitted their Bears */
  public static void BearEmailSendMessage(String msgsubject, String msgText, String msgTo) {
    try {
      BearFrom = props.getProperty("BEARFROM");
      // To = props.getProperty("TO");
      SMTPHost = props.getProperty("SMTPHOST");
      Properties mailprops = new Properties();
      mailprops.put("mail.smtp.host", SMTPHost);

      // create some properties and get the default Session
      Session session = Session.getDefaultInstance(mailprops, null);

      // create a message
      Message msg = new MimeMessage(session);

      // set the from
      InternetAddress from = new InternetAddress(BearFrom);
      msg.setFrom(from);
      InternetAddress[] address = InternetAddress.parse(msgTo);
      msg.setRecipients(Message.RecipientType.TO, address);
      msg.setSubject(msgsubject);
      msg.setContent(msgText, "text/plain");
      Transport.send(msg);
    } // end try
    catch (MessagingException mex) {
      USFEnv.getLog().writeCrit("Message not sent", null, null);
    } catch (Exception ex) {
      USFEnv.getLog().writeCrit("Message not sent", null, null);
    }
  } // end BearEmailSendMessage
コード例 #7
0
  public static void sfSendEmail(String subject, String message) throws Exception {

    String SMTP_HOST_NAME = "smtp.gmail.com";
    String SMTP_PORT = "465";
    // message = "Test Email Notification From Monitor";
    // subject = "Test Email Notification From Monitor";
    String from = "*****@*****.**";
    String[] recipients = {
      "*****@*****.**", "*****@*****.**", "*****@*****.**"
    };
    String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
    // String[] recipients = { "*****@*****.**"};
    // String[] recipients = { "*****@*****.**", "*****@*****.**",
    // "*****@*****.**", "*****@*****.**", "*****@*****.**",
    // "*****@*****.**", "*****@*****.**"};
    // String[] recipients = {"*****@*****.**"};

    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

    boolean debug = true;

    Properties props = new Properties();
    props.put("mail.smtp.host", SMTP_HOST_NAME);
    props.put("mail.smtp.auth", "true");
    // props.put("mail.debug", "true");
    props.put("mail.smtp.port", SMTP_PORT);
    props.put("mail.smtp.socketFactory.port", SMTP_PORT);
    props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
    props.put("mail.smtp.socketFactory.fallback", "false");

    Session session =
        Session.getDefaultInstance(
            props,
            new Authenticator() {

              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(
                    "*****@*****.**", "els102sensorweb");
              }
            });

    // session.setDebug(debug);

    Message msg = new MimeMessage(session);
    InternetAddress addressFrom = new InternetAddress(from);
    msg.setFrom(addressFrom);

    InternetAddress[] addressTo = new InternetAddress[recipients.length];
    for (int i = 0; i < recipients.length; i++) {
      addressTo[i] = new InternetAddress(recipients[i]);
    }
    msg.setRecipients(Message.RecipientType.TO, addressTo);

    // Setting the Subject and Content Type
    msg.setSubject(subject);
    msg.setContent(message, "text/plain");
    Transport.send(msg);

    System.out.println("Sucessfully Sent mail to All Users");
  }
コード例 #8
0
ファイル: SoapConnection.java プロジェクト: forcedotcom/wsc
  private Transport newTransport(ConnectorConfig config) throws ConnectionException {
    if (config.getTransportFactory() != null) {
      Transport t = config.getTransportFactory().createTransport();
      t.setConfig(config);
      return t;
    }

    try {
      Transport t = (Transport) config.getTransport().newInstance();
      t.setConfig(config);
      return t;
    } catch (InstantiationException e) {
      throw new ConnectionException("Failed to create new Transport " + config.getTransport());
    } catch (IllegalAccessException e) {
      throw new ConnectionException("Failed to create new Transport " + config.getTransport());
    }
  }
  public void sendEMailToUser(ICFSecuritySecUserObj toUser, String msgSubject, String msgBody)
      throws IOException, MessagingException, NamingException {

    final String S_ProcName = "sendEMailToUser";

    Properties props = System.getProperties();

    Context ctx = new InitialContext();

    String smtpEmailFrom = (String) ctx.lookup("java:comp/env/CFInternet25SmtpEmailFrom");
    if ((smtpEmailFrom == null) || (smtpEmailFrom.length() <= 0)) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(
              getClass(), S_ProcName, 0, "JNDI lookup for CFInternet25SmtpEmailFrom");
    }

    smtpUsername = (String) ctx.lookup("java:comp/env/CFInternet25SmtpUsername");
    if ((smtpUsername == null) || (smtpUsername.length() <= 0)) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(
              getClass(), S_ProcName, 0, "JNDI lookup for CFInternet25SmtpUsername");
    }

    smtpPassword = (String) ctx.lookup("java:comp/env/CFInternet25SmtpPassword");
    if ((smtpPassword == null) || (smtpPassword.length() <= 0)) {
      throw CFLib.getDefaultExceptionFactory()
          .newNullArgumentException(
              getClass(), S_ProcName, 0, "JNDI lookup for CFInternet25SmtpPassword");
    }

    Session emailSess =
        Session.getInstance(
            props,
            new Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(smtpUsername, smtpPassword);
              }
            });

    MimeMessage msg = new MimeMessage(emailSess);
    msg.setFrom(new InternetAddress(smtpEmailFrom));
    InternetAddress mailTo[] = InternetAddress.parse(toUser.getRequiredEMailAddress(), false);
    msg.setRecipient(Message.RecipientType.TO, mailTo[0]);
    msg.setSubject((msgSubject != null) ? msgSubject : "No subject");
    msg.setSentDate(new Date());
    msg.setContent(msgBody, "text/html");
    msg.saveChanges();

    Transport.send(msg);
  }
コード例 #10
0
ファイル: GPSEvent.java プロジェクト: tedvals/fleetmng
 protected Device loadDevice(String acctID, String devID) {
   if (StringTools.isBlank(acctID)) {
     return this.loadDevice(devID); // load ad ModemID
   } else {
     try {
       Account account = Account.getAccount(acctID);
       if (account == null) {
         Print.logError("Account-ID not found: " + acctID);
         return null;
       } else {
         Device dev = Transport.loadDeviceByTransportID(account, devID);
         return dev;
       }
     } catch (DBException dbe) {
       Print.logError("Error getting Device: " + acctID + "/" + devID + " [" + dbe + "]");
       return null;
     }
   }
 }
コード例 #11
0
  @Override
  public void init() throws TransportInitializationException {
    this.flashPolicyDomain = getConfig().getString(PARAM_FLASHPOLICY_DOMAIN);
    this.flashPolicyPorts = getConfig().getString(PARAM_FLASHPOLICY_PORTS);
    this.flashPolicyServerHost = getConfig().getString(PARAM_FLASHPOLICY_SERVER_HOST);
    this.flashPolicyServerPort = getConfig().getInt(PARAM_FLASHPOLICY_SERVER_PORT, 843);
    this.delegate = getConfig().getWebSocketTransport();

    if (LOGGER.isLoggable(Level.FINE))
      LOGGER.fine(
          getType()
              + " configuration:\n"
              + " - flashPolicyDomain="
              + flashPolicyDomain
              + "\n"
              + " - flashPolicyPorts="
              + flashPolicyPorts
              + "\n"
              + " - flashPolicyServerHost="
              + flashPolicyServerHost
              + "\n"
              + " - flashPolicyServerPort="
              + flashPolicyServerPort
              + "\n"
              + " - websocket delegate="
              + (delegate == null ? "<none>" : delegate.getClass().getName()));

    if (delegate == null)
      throw new TransportInitializationException(
          "No WebSocket transport available for this transport: " + getClass().getName());

    if (flashPolicyServerHost != null && flashPolicyDomain != null && flashPolicyPorts != null) {
      try {
        startFlashPolicyServer();
      } catch (IOException e) {
        // Ignore
      }
    }
  }
コード例 #12
0
  @Override
  public void handle(
      HttpServletRequest request,
      HttpServletResponse response,
      Transport.InboundFactory inboundFactory,
      SessionManager sessionFactory)
      throws IOException {

    String path = request.getPathInfo();
    if (path == null || path.length() == 0 || "/".equals(path)) {
      response.sendError(
          HttpServletResponse.SC_BAD_REQUEST,
          "Invalid " + TransportType.FLASH_SOCKET + " transport request");
      return;
    }
    if (path.startsWith("/")) path = path.substring(1);
    String[] parts = path.split("/");
    if ("GET".equals(request.getMethod()) && TransportType.FLASH_SOCKET.name().equals(parts[0])) {
      if (!FLASHFILE_PATH.equals(path)) {
        delegate.handle(request, response, inboundFactory, sessionFactory);
      } else {
        response.setContentType("application/x-shockwave-flash");
        InputStream is =
            this.getClass()
                .getClassLoader()
                .getResourceAsStream("com/glines/socketio/" + FLASHFILE_NAME);
        OutputStream os = response.getOutputStream();
        try {
          IO.copy(is, os);
        } catch (IOException e) {
          LOGGER.log(Level.FINE, "Error writing " + FLASHFILE_NAME + ": " + e.getMessage(), e);
        }
      }
    } else {
      response.sendError(
          HttpServletResponse.SC_BAD_REQUEST,
          "Invalid " + TransportType.FLASH_SOCKET + " transport request");
    }
  }
コード例 #13
0
ファイル: SoapConnection.java プロジェクト: forcedotcom/wsc
  private XMLizable receive(
      Transport transport, QName responseElement, Class responseType, InputStream in)
      throws IOException, ConnectionException {

    XMLizable result;

    try {

      XmlInputStream xin = new XmlInputStream();
      xin.setInput(in, "UTF-8");

      if (transport.isSuccessful()) {
        result = bind(xin, responseElement, responseType);
      } else {
        throw createException(xin);
      }
    } catch (PullParserException e) {
      throw new ConnectionException("Failed to create/parse xml input stream ", e);
    } finally {
      in.close();
    }

    return result;
  }
コード例 #14
0
ファイル: Emailer.java プロジェクト: baojie1985/MNTG
  public static void sendEmail(String email, String id)
      throws MessagingException, UnsupportedEncodingException {

    Properties props = new Properties();

    props.put("mail.transport.protocol", "smtps");
    props.put("mail.smtps.host", SMTP_HOST_NAME);
    props.put("mail.smtps.auth", "true");

    Session mailSession = Session.getDefaultInstance(props);
    mailSession.setDebug(false);
    Transport transport = mailSession.getTransport();

    MimeMessage message = new MimeMessage(mailSession);
    message.setSubject("Traffic Generation Request #" + id + " has received");

    message.setContent(
        "Hi Sir/Madam, \n\n Your traffic generation request #"
            + id
            + " has been received by DMLab@UMN. \n You will be notified via email "
            + email
            + " , when we finish our processing.\n\n Please be patient. If you have any inquries, please send email to [email protected]. \n\n Thanks, \n DMLab@UMN",
        "text/plain");

    InternetAddress[] mntgAddress = new InternetAddress[1];
    mntgAddress[0] =
        new InternetAddress(
            "*****@*****.**",
            "Minnesota Traffic Generator"); // here we set our email alias and the desired display
    // name
    InternetAddress customer_email = new InternetAddress(email); // customer email

    message.addRecipient(Message.RecipientType.TO, customer_email);

    message.addRecipients(Message.RecipientType.CC, mntgAddress);
    message.addRecipients(Message.RecipientType.BCC, mntgAddress);

    message.setFrom(mntgAddress[0]);
    message.setReplyTo(mntgAddress);
    message.setSender(mntgAddress[0]);

    transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);

    Address[] recipientsTo = message.getRecipients(Message.RecipientType.TO);
    Address[] recipientsCC = message.getRecipients(Message.RecipientType.CC);
    Address[] recipientsBCC = message.getRecipients(Message.RecipientType.BCC);

    Address[] allRecipients =
        new Address[recipientsTo.length + recipientsCC.length + recipientsBCC.length];
    int allIndex = 0;
    for (int i = 0; i < recipientsTo.length; ++i, ++allIndex) {
      allRecipients[allIndex] = recipientsTo[i];
    }
    for (int i = 0; i < recipientsCC.length; ++i, ++allIndex) {
      allRecipients[allIndex] = recipientsCC[i];
    }
    for (int i = 0; i < recipientsBCC.length; ++i, ++allIndex) {
      allRecipients[allIndex] = recipientsBCC[i];
    }

    transport.sendMessage(message, allRecipients);

    transport.close();

    //  InternetAddress notifyAddress = new InternetAddress("*****@*****.**", "Admin MailList");
    // //here we set our email alias and the desired display name
    // sendEmail(mntgAddress[0], notifyAddress,                "Traffic request #" + id + " has just
    // been submitted by user " + email + ".", email);

    /*
     * InternetAddress notifyAddress3 = new
     * InternetAddress("*****@*****.**", "Mohamed Mokbel"); //here we set
     * our email alias and the desired display name
     * sendEmail(mntgAddress[0], notifyAddress3, "Traffic request #" + id +
     * " has just been submitted by user " + email + ".", email);
     *
     */

  }
コード例 #15
0
  public boolean sendMessage() {
    Properties properties = new Properties();
    properties.put("mail.smtp.host", mailHost);
    properties.put("mail.from", Source);
    Session session = Session.getInstance(properties, null);
    try {
      Message message = new MimeMessage(session);
      InternetAddress[] addressTO = null;
      if (this.Destination != null && this.Destination.length() != 0) {
        StringTokenizer TOList = getTokenizer(this.Destination);
        addressTO = new InternetAddress[TOList.countTokens()];
        for (int i = 0; i < addressTO.length; i++) {
          addressTO[i] = new InternetAddress(TOList.nextToken());
          message.addRecipient(Message.RecipientType.TO, addressTO[i]);
        }
      }

      if (this.MsgCC != null && this.MsgCC.length() != 0) {
        StringTokenizer CCList = getTokenizer(this.MsgCC);
        InternetAddress[] addressCC = new InternetAddress[CCList.countTokens()];
        for (int i = 0; i < addressCC.length; i++) {
          addressCC[i] = new InternetAddress(CCList.nextToken());
          message.addRecipient(Message.RecipientType.CC, addressCC[i]);
        }
      }
      message.setFrom(new InternetAddress(Source));
      message.setSubject(Subject);
      Content = getHtmlHeader() + Content + getHtmlFooter();
      Content = Content.replaceAll("\\{style\\}", MailStyle);

      BodyPart messageBodyPart = new MimeBodyPart();

      messageBodyPart.setText(Content);
      messageBodyPart.setContent(Content, "text/html");

      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(messageBodyPart);

      Iterator it = this.BinaryAttachments.iterator();
      while (it.hasNext()) {
        ByteArrayDataSource bads = (ByteArrayDataSource) it.next();

        messageBodyPart = new MimeBodyPart();
        // messageBodyPart.setDataHandler(new DataHandler(new FileDataSource("c:/test/tom.jpg")));
        messageBodyPart.setDataHandler(new DataHandler(bads));
        messageBodyPart.setFileName(bads.getName());

        multipart.addBodyPart(messageBodyPart);
      }
      message.setContent(multipart);

      Transport transport = session.getTransport(addressTO[0]);
      transport.addConnectionListener(new ConnectionHandler());
      transport.addTransportListener(new TransportHandler());
      transport.connect();
      transport.send(message);
      return true;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
コード例 #16
0
  public static void sendEmail(String subject, String message) throws Exception {
    /*
    String mailhost = "mail.vancouver.wsu.edu";
    String cc = null;
    String bcc = null;
    boolean debug = false;
    String file = null;
    String mailer = "msgsend";
    String sender = "mail.vancouver.wsu.edu";


       Properties props = System.getProperties();

       if (mailhost != null)
    props.put("mail.smtp.host", mailhost);

       // Get a Session object
       Session session = Session.getInstance(props, null);

    if (debug)
    session.setDebug(true);

       // construct the message
       Message msg = new MimeMessage(session);
       if (sender != null)
    msg.setFrom(new InternetAddress(sender));
       else
    msg.setFrom();

       msg.setRecipients(Message.RecipientType.TO,
    			InternetAddress.parse(receivers[0], false));

       if (cc != null)
    msg.setRecipients(Message.RecipientType.CC,
    			InternetAddress.parse(cc, false));
       if (bcc != null)
    msg.setRecipients(Message.RecipientType.BCC,
    			InternetAddress.parse(bcc, false));

       msg.setSubject(subject);

       String text = content;

       if (file != null) {
    // Attach the specified file.
    // We need a multipart message to hold the attachment.
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setText(text);
    MimeBodyPart mbp2 = new MimeBodyPart();
    mbp2.attachFile(file);
    MimeMultipart mp = new MimeMultipart();
    mp.addBodyPart(mbp1);
    mp.addBodyPart(mbp2);
    msg.setContent(mp);
       } else {
    // If the desired charset is known, you can use
    // setText(text, charset)
    msg.setText(text);
       }

       msg.setHeader("X-Mailer", mailer);
       msg.setSentDate(new Date());

       // send the thing off
       Transport.send(msg);

       System.out.println("\nMail was sent successfully.");
    */

    // Xiaogang: checkbox
    // System.out.println("sendemail"+MainFrame.EMAIL_ENABLE);
    if (MainFrame.EMAIL_ENABLE == false) return;

    String SMTP_HOST_NAME = "smtp.gmail.com";
    String SMTP_PORT = "465";
    // message = "Test Email Notification From Monitor";
    // subject = "Test Email Notification From Monitor";
    String from = "*****@*****.**";
    String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
    String[] recipients = {
      "*****@*****.**", "*****@*****.**", "*****@*****.**"
    };
    // String[] recipients = { "*****@*****.**"};
    // String[] recipients = { , "*****@*****.**", "*****@*****.**",
    // "*****@*****.**", "*****@*****.**"};
    // String[] recipients = {"*****@*****.**"};

    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

    boolean debug = true;

    Properties props = new Properties();
    props.put("mail.smtp.host", SMTP_HOST_NAME);
    props.put("mail.smtp.auth", "true");
    // props.put("mail.debug", "true");
    props.put("mail.smtp.port", SMTP_PORT);
    props.put("mail.smtp.socketFactory.port", SMTP_PORT);
    props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
    props.put("mail.smtp.socketFactory.fallback", "false");

    Session session =
        Session.getDefaultInstance(
            props,
            new Authenticator() {

              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(
                    "*****@*****.**", "els102sensorweb");
              }
            });

    // session.setDebug(debug);

    Message msg = new MimeMessage(session);
    InternetAddress addressFrom = new InternetAddress(from);
    msg.setFrom(addressFrom);

    InternetAddress[] addressTo = new InternetAddress[recipients.length];
    for (int i = 0; i < recipients.length; i++) {
      addressTo[i] = new InternetAddress(recipients[i]);
    }
    msg.setRecipients(Message.RecipientType.TO, addressTo);

    // Setting the Subject and Content Type
    msg.setSubject(subject);
    msg.setContent(message, "text/plain");
    Transport.send(msg);

    System.out.println("Sucessfully Sent mail to All Users");
  }