Example usage for java.util Properties Properties

List of usage examples for java.util Properties Properties

Introduction

In this page you can find the example usage for java.util Properties Properties.

Prototype

public Properties() 

Source Link

Document

Creates an empty property list with no default values.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    URLName server = new URLName("protocol://username@host/foldername");

    Session session = Session.getDefaultInstance(new Properties(), new MailAuthenticator());

    Folder folder = session.getFolder(server);
    if (folder == null) {
        System.out.println("Folder " + server.getFile() + " not found.");
        System.exit(1);//from w  ww .j  av a  2s. c  om
    }
    folder.open(Folder.READ_ONLY);

    Message[] messages = folder.getMessages();
    for (int i = 0; i < messages.length; i++) {
        System.out.println(messages[i].getSize() + " bytes long.");
        System.out.println(messages[i].getLineCount() + " lines.");
        String disposition = messages[i].getDisposition();
        if (disposition == null) {
            ; // do nothing
        } else if (disposition.equals(Part.INLINE)) {
            System.out.println("This part should be displayed inline");
        } else if (disposition.equals(Part.ATTACHMENT)) {
            System.out.println("This part is an attachment");
            String fileName = messages[i].getFileName();
            System.out.println("The file name of this attachment is " + fileName);
        }
        String description = messages[i].getDescription();
        if (description != null) {
            System.out.println("The description of this message is " + description);
        }
    }
    folder.close(false);
}

From source file:TestDSBind.java

public static void main(String args[]) throws SQLException, NamingException {

    // For this to work you will need to create the
    // directories /JNDI/JDBC on your file system first
    Context ctx = null;// ww w. j  av a 2 s  . co  m
    try {
        Properties prop = new Properties();
        prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
        prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC");
        ctx = new InitialContext(prop);
    } catch (NamingException ne) {
        System.err.println(ne.getMessage());
    }

    OracleDataSource ds = new OracleDataSource();
    ds.setDriverType("thin");
    ds.setServerName("dssw2k01");
    ds.setPortNumber(1521);
    ds.setDatabaseName("orcl");
    ds.setUser("scott");
    ds.setPassword("tiger");

    ctx.bind("joe", ds);
}

From source file:Main.java

public static void main(String[] args) {
    String from = "user@some-domain.com";
    String to = "user@some-domain.com";
    String subject = "Hi There...";
    String text = "How are you?";

    Properties properties = new Properties();
    properties.put("mail.smtp.host", "smtp.some-domain.com");
    properties.put("mail.smtp.port", "25");
    Session session = Session.getDefaultInstance(properties, null);

    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject(subject);//from w w  w . ja va  2 s . c o  m
    message.setText(text);

    Transport.send(message);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    URLName server = new URLName("protocol://username@host/foldername");

    Session session = Session.getDefaultInstance(new Properties(), new MailAuthenticator());

    Folder folder = session.getFolder(server);
    if (folder != null) {
        folder.open(Folder.READ_ONLY);/* www  .j  a v  a 2  s .c  om*/

        Message[] messages = folder.getMessages();
        for (int i = 0; i < messages.length; i++) {
            System.out.println((i + 1));
            Enumeration headers = messages[i].getAllHeaders();
            while (headers.hasMoreElements()) {
                Header h = (Header) headers.nextElement();
                System.out.println(h.getName() + ": " + h.getValue());
            }
        }
        folder.close(false);
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    URLName server = new URLName("protocol://username@host/foldername");

    Session session = Session.getDefaultInstance(new Properties(), new MailAuthenticator());

    Folder folder = session.getFolder(server);
    if (folder == null) {
        System.out.println("Folder " + server.getFile() + " not found.");
        System.exit(1);/* w w  w . j a  v  a2s  .  c  o  m*/
    }
    folder.open(Folder.READ_ONLY);

    Message[] messages = folder.getMessages();
    for (int i = 0; i < messages.length; i++) {
        System.out.println("Message " + (i + 1));

        System.out.println("From: " + InternetAddress.toString(messages[i].getFrom()));
        System.out.println("Reply-to: " + InternetAddress.toString(messages[i].getReplyTo()));
        String to = InternetAddress.toString(messages[i].getRecipients(Message.RecipientType.TO));
        System.out.println("To: " + to);
        String cc = InternetAddress.toString(messages[i].getRecipients(Message.RecipientType.CC));
        System.out.println("Cc: " + cc);
        String bcc = InternetAddress.toString(messages[i].getRecipients(Message.RecipientType.BCC));
        System.out.println("Bcc: " + bcc);
        System.out.println("Subject: " + messages[i].getSubject());
        System.out.println("Sent: " + messages[i].getSentDate());
        System.out.println("Received: " + messages[i].getReceivedDate());
    }
    folder.close(false);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    URLName server = new URLName("protocol://username@host/foldername");

    Session session = Session.getDefaultInstance(new Properties(), new MailAuthenticator());

    Folder folder = session.getFolder(server);
    if (folder == null) {
        System.out.println("Folder " + server.getFile() + " not found.");
        System.exit(1);//from   w w  w  .  j  av a2s .  c  o  m
    }
    folder.open(Folder.READ_ONLY);

    Message[] messages = folder.getMessages();
    for (int i = 0; i < messages.length; i++) {
        System.out.println(messages[i].getSize() + " bytes long.");
        System.out.println(messages[i].getLineCount() + " lines.");
    }
    folder.close(false);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URLName server = new URLName("protocol://username@host/foldername");
    Session session = Session.getDefaultInstance(new Properties(), new MailAuthenticator());
    Folder folder = session.getFolder(server);
    if (folder == null) {
        System.out.println("Folder " + server.getFile() + " not found.");
        System.exit(1);/*w ww. jav a2  s.  c  o  m*/
    }
    folder.open(Folder.READ_ONLY);
    Message[] messages = folder.getMessages();
    for (int i = 0; i < messages.length; i++) {
        System.out.println("From: " + InternetAddress.toString(messages[i].getFrom()));
        System.out.println("Reply-to: " + InternetAddress.toString(messages[i].getReplyTo()));
        System.out.println(
                "To: " + InternetAddress.toString(messages[i].getRecipients(Message.RecipientType.TO)));
        System.out.println(
                "Cc: " + InternetAddress.toString(messages[i].getRecipients(Message.RecipientType.CC)));
        System.out.println(
                "Bcc: " + InternetAddress.toString(messages[i].getRecipients(Message.RecipientType.BCC)));
        System.out.println("Subject: " + messages[i].getSubject());
        System.out.println("Sent: " + messages[i].getSentDate());
        System.out.println("Received: " + messages[i].getReceivedDate());

        if (messages[i].isSet(Flags.Flag.DELETED)) {
            System.out.println("Deleted");
        }
        if (messages[i].isSet(Flags.Flag.ANSWERED)) {
            System.out.println("Answered");
        }
        if (messages[i].isSet(Flags.Flag.DRAFT)) {
            System.out.println("Draft");
        }
        if (messages[i].isSet(Flags.Flag.FLAGGED)) {
            System.out.println("Marked");
        }
        if (messages[i].isSet(Flags.Flag.RECENT)) {
            System.out.println("Recent");
        }
        if (messages[i].isSet(Flags.Flag.SEEN)) {
            System.out.println("Read");
        }
        if (messages[i].isSet(Flags.Flag.USER)) {
            // We don't know what the user flags might be in advance
            // so they're returned as an array of strings
            String[] userFlags = messages[i].getFlags().getUserFlags();
            for (int j = 0; j < userFlags.length; j++) {
                System.out.println("User flag: " + userFlags[j]);
            }
        }
    }
    folder.close(false);
}

From source file:GetMessageExample.java

public static void main(String args[]) throws Exception {
    if (args.length != 3) {
        System.err.println("Usage: java MailExample host username password");
        System.exit(-1);//  w  w w  .  j a  v  a2s.  c  o m
    }

    String host = args[0];
    String username = args[1];
    String password = args[2];

    // Create empty properties
    Properties props = new Properties();

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

    // Get the store
    Store store = session.getStore("pop3");
    store.connect(host, username, password);

    // Get folder
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_ONLY);

    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    // Get directory
    Message message[] = folder.getMessages();
    for (int i = 0, n = message.length; i < n; i++) {
        System.out.println(i + ": " + message[i].getFrom()[0] + "\t" + message[i].getSubject());

        System.out.println("Read message? [YES to read/QUIT to end]");
        String line = reader.readLine();
        if ("YES".equalsIgnoreCase(line)) {
            System.out.println(message[i].getContent());
        } else if ("QUIT".equalsIgnoreCase(line)) {
            break;
        }
    }

    // Close connection
    folder.close(false);
    store.close();
}

From source file:TestDSLookUp.java

public static void main(String[] args) throws SQLException, NamingException {

    Context ctx = null;//from  w w  w  .  j  a  v a  2  s.c om
    try {
        Properties prop = new Properties();
        prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
        prop.setProperty(Context.PROVIDER_URL, "file:/JNDI/JDBC");
        ctx = new InitialContext(prop);
    } catch (NamingException ne) {
        System.err.println(ne.getMessage());
    }

    DataSource ds = (DataSource) ctx.lookup("joe");
    Connection conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery(
            "select 'Hello Thin driver data source tester '||" + "initcap(USER)||'!' result from dual");
    if (rset.next())
        System.out.println(rset.getString(1));
    rset.close();
    stmt.close();
    conn.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {

    URLName server = new URLName("protocol://username@host/foldername");

    Session session = Session.getDefaultInstance(new Properties(), new MailAuthenticator());

    Folder folder = session.getFolder(server);
    if (folder == null) {
        System.out.println("Folder " + server.getFile() + " not found.");
        System.exit(1);/*from   w w w  .  j av a 2 s  .  com*/
    }
    folder.open(Folder.READ_ONLY);

    // Get the messages from the server
    Message[] messages = folder.getMessages();
    for (int i = 0; i < messages.length; i++) {
        // Get the headers
        System.out.println("From: " + InternetAddress.toString(messages[i].getFrom()));
        System.out.println("Reply-to: " + InternetAddress.toString(messages[i].getReplyTo()));
        System.out.println(
                "To: " + InternetAddress.toString(messages[i].getRecipients(Message.RecipientType.TO)));
        System.out.println(
                "Cc: " + InternetAddress.toString(messages[i].getRecipients(Message.RecipientType.CC)));
        System.out.println(
                "Bcc: " + InternetAddress.toString(messages[i].getRecipients(Message.RecipientType.BCC)));
        System.out.println("Subject: " + messages[i].getSubject());

        System.out.println("Sent: " + messages[i].getSentDate());
        System.out.println("Received: " + messages[i].getReceivedDate());

        if (messages[i].isSet(Flags.Flag.DELETED)) {
            System.out.println("Deleted");
        }
        if (messages[i].isSet(Flags.Flag.ANSWERED)) {
            System.out.println("Answered");
        }
        if (messages[i].isSet(Flags.Flag.DRAFT)) {
            System.out.println("Draft");
        }
        if (messages[i].isSet(Flags.Flag.FLAGGED)) {
            System.out.println("Marked");
        }
        if (messages[i].isSet(Flags.Flag.RECENT)) {
            System.out.println("Recent");
        }
        if (messages[i].isSet(Flags.Flag.SEEN)) {
            System.out.println("Read");
        }
        if (messages[i].isSet(Flags.Flag.USER)) {
            // We don't know what the user flags might be in advance
            // so they're returned as an array of strings
            String[] userFlags = messages[i].getFlags().getUserFlags();
            for (int j = 0; j < userFlags.length; j++) {
                System.out.println("User flag: " + userFlags[j]);
            }
        }
    }
    folder.close(false);
}