public static void main(String[] args) {
    // Get the Properties and Create a default session
    Properties prop = System.getProperties();
    prop.setProperty("mail.server.com", "127.0.0.1");
    Session session = Session.getDefaultInstance(prop);

    try {
      // Set the mail headers
      MimeMessage msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress("*****@*****.**"));
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress("*****@*****.**"));
      msg.setSubject("First Mail");

      // Create the mime body and attachments
      MimeBodyPart msgBody = new MimeBodyPart();
      msgBody.setContent("Hello World", "text/html");

      MimeBodyPart attFile = new MimeBodyPart();
      attFile.attachFile("RecvMail.java");

      Multipart partMsg = new MimeMultipart();
      partMsg.addBodyPart(msgBody);
      partMsg.addBodyPart(attFile);

      msg.setContent(partMsg);

      Transport.send(msg);

      System.out.println("Message Successfully sent...");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    String to = "*****@*****.**"; // change accordingly
    String from = "*****@*****.**"; // change accordingly
    String host = "smtp.gmail.com"; // or IP address

    // Get the session object
    Properties properties = System.getProperties();
    properties.setProperty("mail.smtp.host", host);
    Session session = Session.getDefaultInstance(properties);

    // compose the message
    try {
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(from));
      message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
      message.setSubject("Ping");
      message.setText("Hello, this is example of sending email  ");

      // Send message
      Transport.send(message);
      System.out.println("message sent successfully....");

    } catch (MessagingException mex) {
      mex.printStackTrace();
    }
  }
  /**
   * Creates a new Socket connected to the given IP address. The method uses connection settings
   * supplied in the constructor for connecting the socket.
   *
   * @param address the IP address to connect to
   * @return connected socket
   * @throws java.net.UnknownHostException if the hostname of the address or the proxy cannot be
   *     resolved
   * @throws java.io.IOException if an I/O error occured while connecting to the remote end or to
   *     the proxy
   */
  private Socket createSocket(InetSocketAddress address, int timeout) throws IOException {
    String socksProxyHost = System.getProperty("socksProxyHost");
    System.getProperties().remove("socksProxyHost");
    try {
      ConnectivitySettings cs = lastKnownSettings.get(address);
      if (cs != null) {
        try {
          return createSocket(cs, address, timeout);
        } catch (IOException e) {
          // not good anymore, try all proxies
          lastKnownSettings.remove(address);
        }
      }

      URI uri = addressToURI(address, "socket");
      try {
        return createSocket(uri, address, timeout);
      } catch (IOException e) {
        // we will also try https
      }

      uri = addressToURI(address, "https");
      return createSocket(uri, address, timeout);

    } finally {
      if (socksProxyHost != null) {
        System.setProperty("socksProxyHost", socksProxyHost);
      }
    }
  }
Beispiel #4
1
  public static void sendMail(String mailMessage) {

    String to = "*****@*****.**";
    String from = "FlotaWeb";
    String host = "mail.arabesque.ro";

    Properties properties = System.getProperties();
    properties.setProperty("mail.smtp.host", host);

    Session session = Session.getDefaultInstance(properties);

    try {
      MimeMessage message = new MimeMessage(session);

      message.setFrom(new InternetAddress(from));

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

      message.setSubject("Distributie");

      message.setText(mailMessage);

      Transport.send(message);

    } catch (MessagingException e) {
      logger.error(Utils.getStackTrace(e));
    }
  }
 public static String getNSSLibDir() throws Exception {
   Properties props = System.getProperties();
   String osName = props.getProperty("os.name");
   if (osName.startsWith("Win")) {
     osName = "Windows";
     NSPR_PREFIX = "lib";
   }
   String osid =
       osName
           + "-"
           + props.getProperty("os.arch")
           + "-"
           + props.getProperty("sun.arch.data.model");
   String ostype = osMap.get(osid);
   if (ostype == null) {
     System.out.println("Unsupported OS, skipping: " + osid);
     return null;
     //          throw new Exception("Unsupported OS " + osid);
   }
   if (ostype.length() == 0) {
     System.out.println("NSS not supported on this platform, skipping test");
     return null;
   }
   String libdir = NSS_BASE + SEP + "lib" + SEP + ostype + SEP;
   System.setProperty("pkcs11test.nss.libdir", libdir);
   return libdir;
 }
  public static void main(String[] args) throws MessagingException, IOException {
    IMAPFolder folder = null;
    Store store = null;
    String subject = null;
    Flag flag = null;
    try {
      Properties props = System.getProperties();
      props.setProperty("mail.store.protocol", "imaps");
      props.setProperty("mail.imap.host", "imap.googlemail.com");
      SimpleAuthenticator authenticator =
          new SimpleAuthenticator("*****@*****.**", "hhy8611hhyy");
      Session session = Session.getDefaultInstance(props, null);
      // Session session = Session.getDefaultInstance(props, authenticator);

      store = session.getStore("imaps");
      //          store.connect("imap.googlemail.com","*****@*****.**", "hhy8611hhyy");
      // store.connect("imap.googlemail.com","*****@*****.**", "hhy8611hhyy");

      store.connect("*****@*****.**", "hhy8611hhy");
      // folder = (IMAPFolder) store.getFolder("[Gmail]/Spam"); // This doesn't work for other email
      // account
      folder = (IMAPFolder) store.getFolder("inbox"); // This works for both email account

      if (!folder.isOpen()) folder.open(Folder.READ_WRITE);
      Message[] messages = messages = folder.getMessages(150, 150); // folder.getMessages();
      System.out.println("No of get Messages : " + messages.length);
      System.out.println("No of Messages : " + folder.getMessageCount());
      System.out.println("No of Unread Messages : " + folder.getUnreadMessageCount());
      System.out.println("No of New Messages : " + folder.getNewMessageCount());
      System.out.println(messages.length);
      for (int i = 0; i < messages.length; i++) {

        System.out.println(
            "*****************************************************************************");
        System.out.println("MESSAGE " + (i + 1) + ":");
        Message msg = messages[i];
        // System.out.println(msg.getMessageNumber());
        // Object String;
        // System.out.println(folder.getUID(msg)

        subject = msg.getSubject();

        System.out.println("Subject: " + subject);
        System.out.println("From: " + msg.getFrom()[0]);
        System.out.println("To: " + msg.getAllRecipients()[0]);
        System.out.println("Date: " + msg.getReceivedDate());
        System.out.println("Size: " + msg.getSize());
        System.out.println(msg.getFlags());
        System.out.println("Body: \n" + msg.getContent());
        System.out.println(msg.getContentType());
      }
    } finally {
      if (folder != null && folder.isOpen()) {
        folder.close(true);
      }
      if (store != null) {
        store.close();
      }
    }
  }
Beispiel #7
0
 @Test
 public void test117() {
   System.getProperties().put("default.template_lang.impl", ICodeType.DefImpl.CSV);
   t = "@for(\"FirstName,LastName,Email\"){@__sep}";
   s = r(t);
   eq("FirstName,LastName,Email");
 }
  public MiniFramework(Map<Object, Object> properties) {
    this.properties = new Properties(System.getProperties());
    this.properties.putAll(properties);

    bundles.put(new Long(0), this);
    last = loader = getClass().getClassLoader();
  }
  @Test
  public void testClose() throws Exception {
    // use NullSender
    Properties props = System.getProperties();
    props.setProperty(Config.FLUENT_SENDER_CLASS, NullSender.class.getName());

    // create logger objects
    FluentLogger.getLogger("tag1");
    FluentLogger.getLogger("tag2");
    FluentLogger.getLogger("tag3");

    Map<String, FluentLogger> loggers;
    {
      loggers = FluentLogger.getLoggers();
      assertEquals(3, loggers.size());
    }

    // close and delete
    FluentLogger.closeAll();
    {
      loggers = FluentLogger.getLoggers();
      assertEquals(0, loggers.size());
    }

    props.remove(Config.FLUENT_SENDER_CLASS);
  }
  public static Properties getSystemProperties() {
    Properties res = ourSystemProperties;
    if (res == null) {
      res = new Properties();
      res.putAll(System.getProperties());

      for (Iterator<Object> itr = res.keySet().iterator(); itr.hasNext(); ) {
        final String propertyName = itr.next().toString();
        if (propertyName.startsWith("idea.")) {
          itr.remove();
        }
      }

      for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
        String key = entry.getKey();
        if (key.startsWith("=")) {
          continue;
        }
        if (SystemInfo.isWindows) {
          key = key.toUpperCase();
        }
        res.setProperty("env." + key, entry.getValue());
      }

      ourSystemProperties = res;
    }
    return res;
  }
Beispiel #11
0
public class StringCopy implements IGenerator {

  protected static String nl;

  public static synchronized StringCopy create(String lineSeparator) {
    nl = lineSeparator;
    StringCopy result = new StringCopy();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "#1#.set";
  protected final String TEXT_2 = "(";
  protected final String TEXT_3 = ");" + NL + "\t";

  public String generate(Object argument) {
    final StringBuffer stringBuffer = new StringBuffer();
    Attribute attVar = (Attribute) argument;
    stringBuffer.append(TEXT_1);
    stringBuffer.append(attVar.getUpperCaseName());
    stringBuffer.append(TEXT_2);
    stringBuffer.append("this.a" + attVar.getUpperCaseName());
    stringBuffer.append(TEXT_3);
    return stringBuffer.toString();
  }
}
Beispiel #12
0
  public static void main(String[] args) {

    Properties prop = System.getProperties();

    // 因为Properties是Hashtable的子类,也就是Map集合的一个子类对象。
    // 那么可以通过map的方法取出该集合中的元素。
    // 该集合中存储的都是字符串。没有泛型定义。

    // 如何在系统中自定义一些系统信息

    System.setProperty("mykey", "myvalue");

    // 获取指定属性信息

    String osvalue = System.getProperty("os.name");

    System.out.println("value=" + osvalue);

    // 可不可以在JVM启动时,动态地加载一些属性信息
    // -D<name>=<value>  设置系统属性

    // 获取所有属性信息

    for (Object obj : prop.keySet()) {
      String value = (String) prop.get(obj);

      System.out.println(obj + "::" + value);
    }
  }
Beispiel #13
0
  /** print out some info about the system and JVM etc. */
  public static void show() {
    Properties prop = System.getProperties();

    JDDConsole.out.println(
        "Using JDD build " + jdd.Version.build + " on " + (new Date()).toString() + "\n");
    JDDConsole.out.print(
        "Using " + prop.getProperty("java.vendor") + " JRE " + prop.getProperty("java.version"));
    String jit = prop.getProperty("java.compiler");
    if (jit != null) JDDConsole.out.print(", " + jit + " JIT in");
    JDDConsole.out.println(" " + prop.getProperty("java.vm.name"));

    JDDConsole.out.println(
        "OS "
            + prop.getProperty("os.name")
            + " on "
            + rt.availableProcessors()
            + " "
            + prop.getProperty("os.arch")
            + " CPU(s)");
    JDDConsole.out.print("Total JRE memory: ");
    Digits.printNumber1024(rt.maxMemory());
    JDDConsole.out.print(", memory currently reserved by the JRE: ");
    Digits.printNumber1024(usedMemory());
    JDDConsole.out.println("\n");
  }
  @Override
  public final void runBare() throws Throwable {
    // Patch a bug with maven that does not pass properly the system property
    // with an empty value
    if ("org.hsqldb.jdbcDriver".equals(System.getProperty("gatein.test.datasource.driver"))) {
      System.setProperty("gatein.test.datasource.password", "");
    }

    //
    log.info("Running unit test:" + getName());
    for (Map.Entry<?, ?> entry : System.getProperties().entrySet()) {
      if (entry.getKey() instanceof String) {
        String key = (String) entry.getKey();
        log.debug(key + "=" + entry.getValue());
      }
    }

    //
    beforeRunBare();

    //
    try {
      super.runBare();
      log.info("Unit test " + getName() + " completed");
    } catch (Throwable throwable) {
      log.error("Unit test " + getName() + " did not complete", throwable);

      //
      throw throwable;
    } finally {
      afterRunBare();
    }
  }
Beispiel #15
0
 public Dictionary getProperties() {
   Hashtable p = new Hashtable(props_default);
   p.putAll(System.getProperties());
   p.putAll(props);
   p.put(KEY_KEYS, makeKeys());
   return p;
 }
 public static void basic_putenv(Object name, Object value) {
   String name_string = SmartEiffelRuntime.NullTerminatedBytesToString(name);
   String value_string = SmartEiffelRuntime.NullTerminatedBytesToString(value);
   Properties props = System.getProperties();
   props.put(name_string, value_string);
   System.setProperties(props);
   return;
 }
Beispiel #17
0
 public static void copySystemProperties(Properties configProps) {
   for (Enumeration e = System.getProperties().propertyNames(); e.hasMoreElements(); ) {
     String key = (String) e.nextElement();
     if (key.startsWith("felix.") || key.startsWith("org.osgi.framework.")) {
       configProps.setProperty(key, System.getProperty(key));
     }
   }
 }
  /**
   * Adds the keys/properties from an application-specific properties file to the System Properties.
   * The application-specific properties file MUST reside in a directory listed on the CLASSPATH.
   *
   * @param propsFileName The name of an application-specific properties file.
   */
  public static void addToSystemPropertiesFromPropsFile(String propsFileName) {
    Properties props = ResourceLoader.getAsProperties(propsFileName),
        sysProps = System.getProperties();

    // Add the keys/properties from the application-specific properties  to the System Properties.

    sysProps.putAll(props);
  }
Beispiel #19
0
 /** sometimes call by sample application, at that time normally set some properties directly */
 private Configure() {
   Properties p = new Properties();
   Map args = new HashMap();
   args.putAll(System.getenv());
   args.putAll(System.getProperties());
   p.putAll(args);
   this.property = p;
   reload(false);
 }
 @After
 public void tearDown() throws Exception {
   if (sysProp == null) {
     System.getProperties().remove("java.naming.factory.initial");
   } else {
     System.setProperty("java.naming.factory.initial", sysProp);
   }
   super.tearDown();
   mockControl.reset();
 }
 @Test
 public void systemPropertyIKeyBeforeConfigurationIKeyTest() {
   try {
     System.setProperty(
         TelemetryConfigurationFactory.EXTERNAL_PROPERTY_IKEY_NAME, APP_INSIGHTS_IKEY_TEST_VALUE);
     ikeyTest(MOCK_IKEY, APP_INSIGHTS_IKEY_TEST_VALUE);
   } finally {
     // Avoid any influence on other unit tests
     System.getProperties().remove(TelemetryConfigurationFactory.EXTERNAL_PROPERTY_IKEY_NAME);
   }
 }
Beispiel #22
0
 public static void printSystemProperties() {
   java.util.Enumeration e = System.getProperties().propertyNames();
   while (e.hasMoreElements()) {
     String prop = (String) e.nextElement();
     String out = prop;
     out += " = ";
     out += System.getProperty(prop);
     out += "\n";
     System.out.println(out);
   }
 }
  public Map getSystemProperties() {
    Map map = new HashMap();
    Properties props = System.getProperties();

    for (Enumeration e = props.keys(); e.hasMoreElements(); ) {
      String key = (String) e.nextElement();
      String val = (String) props.get(key);
      map.put(key, val);
    }
    return map;
  }
Beispiel #24
0
    private static void linkGlobalProperty() {
        List<Class> clzs = BeanUtils.scanClass("org.zstack", GlobalPropertyDefinition.class);

        Map<String, String> propertiesMap = new HashMap<String, String>();
        for (final String name: System.getProperties().stringPropertyNames()) {
            propertiesMap.put(name, System.getProperty(name));
        }

        for (Class clz : clzs) {
            linkGlobalProperty(clz, propertiesMap);
        }
    }
Beispiel #25
0
  @Test
  public void test122() {
    System.getProperties()
        .put(RythmConfigurationKey.DEFAULT_CODE_TYPE_IMPL.getKey(), ICodeType.DefImpl.HTML);
    t = "@args String src;<script src='@src'></script><script src='@src'></script>";
    s = r(t, "/js/abc");
    eq("<script src='/js/abc'></script><script src='/js/abc'></script>");

    t = "@args models.Foo foo;<script src='@foo.bar()._x()'></script>";
    s = r(t, new Foo());
    eq("<script src=''></script>");
  }
Beispiel #26
0
 @Test
 public void test155() {
   String x = "\uD83D\uDE30";
   assertEquals(x, S.escapeCSV(x).toString());
   assertEquals(x, Escape.CSV.apply(x).toString());
   System.getProperties()
       .setProperty(
           RythmConfigurationKey.DEFAULT_CODE_TYPE_IMPL.getKey(),
           "org.rythmengine.extension.ICodeType.DefImpl.CSV");
   t = "@s";
   s = r(t, x);
   eq(x);
 }
  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);
  }
Beispiel #28
0
    public static Map<String, String> getGlobalPropertiesStartWith(String prefix) {
        Properties props = System.getProperties();
        Enumeration e = props.propertyNames();

        Map<String, String> ret = new HashMap<String, String>();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            if (key.startsWith(prefix)) {
                ret.put(key, System.getProperty(key));
            }
        }

        return ret;
    }
Beispiel #29
0
  public static void dumpSystemProperties() {
    out("System Properties:");

    Properties props = System.getProperties();

    Iterator it = props.keySet().iterator();

    while (it.hasNext()) {

      String name = (String) it.next();

      out("\t".concat(name).concat(" = '").concat(props.get(name).toString()).concat("'"));
    }
  }
Beispiel #30
0
  Properties runProperties() {
    Properties props = new Properties();
    props.putAll(this.properties);

    Properties sysProps = System.getProperties();

    Set<String> names = sysProps.stringPropertyNames();
    for (String name : names) {
      if (name.startsWith("jboss") || name.startsWith("wildfly") || name.startsWith("swarm")) {
        props.put(name, sysProps.get(name));
      }
    }

    return props;
  }