Esempio n. 1
0
  /** 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
Esempio n. 2
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");
  }
Esempio n. 3
0
 protected void fillSubject(Message email, Execution execution, JCRSessionWrapper session)
     throws MessagingException {
   String subject = getTemplate().getSubject();
   if (subject != null) {
     try {
       String evaluatedSubject =
           evaluateExpression(execution, subject, session).replaceAll("[\r\n]", "");
       email.setSubject(WordUtils.abbreviate(evaluatedSubject, 60, 74, "..."));
     } catch (RepositoryException e) {
       logger.error(e.getMessage(), e);
     } catch (ScriptException e) {
       logger.error(e.getMessage(), e);
     }
   }
 }
  protected void sendNotif(ICNotification notif, Object target) throws Exception {
    // Creating message
    Message s_message = new MimeMessage(session);

    // Set message properties
    s_message.setFrom(new InternetAddress(sender));
    s_message.setSubject(notif.getAttrib(NOTIF_SUBJECT));
    s_message.setText(notif.getAttrib(NOTIF_CONTENT));
    s_message.setSentDate(new Date(notif.getTimeMsec()));

    for (Iterator it = ((Set) target).iterator(); it.hasNext(); ) {
      s_message.addRecipient(Message.RecipientType.TO, new InternetAddress((String) it.next()));
    }
    // Sending message
    transport.sendMessage(s_message, s_message.getAllRecipients());
  }
Esempio n. 5
0
  public static void sendSSLMessage(
      String recipients[], String subject, String message, String from) throws MessagingException {
    boolean debug = true;

    /*Da errore ma non c'e' da preoccuparsi*/
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

    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 javax.mail.Authenticator() {
              protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("*****@*****.**", "magicrestaurant");
              }
            });

    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);
  }
Esempio n. 6
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");
  }