当前位置: 首页>>代码示例>>Java>>正文


Java Store类代码示例

本文整理汇总了Java中javax.mail.Store的典型用法代码示例。如果您正苦于以下问题:Java Store类的具体用法?Java Store怎么用?Java Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Store类属于javax.mail包,在下文中一共展示了Store类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEmail

import javax.mail.Store; //导入依赖的package包/类
public void getEmail() throws MessagingException, IOException {
    Session session = Session.getDefaultInstance(System.getProperties(),null);
    Store store = null;
    store = session.getStore("imaps");

    // store.connect(this.host, this.userName, this.password);

    // Get default folder
    Folder folder = store.getDefaultFolder();
    folder.getMessages();
    folder.getNewMessageCount();
    Message m = folder.getMessage(0);
    m.getMessageNumber();
    m.getAllRecipients();
    m.getReceivedDate();
    m.getFrom();
    m.getSubject();
    m.getReplyTo();
    m.getContent();
    m.getSize();

    // Get any folder by name
    Folder[] folderList = folder.list();
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:25,代码来源:PNetwork.java

示例2: closeStoreConnection

import javax.mail.Store; //导入依赖的package包/类
/**
 * Close connection
 * <b>Note</b>Internal method
 * @throws MessagingException
 */
public void closeStoreConnection(
                                  boolean storeConnected ) throws MessagingException {

    if (storeConnected) {
        // the folder is empty when the message is not loaded from IMAP server, but from a file
        Folder imapFolder = message.getFolder();
        if (imapFolder == null) {
            imapFolder = partOfImapFolder; // in case of nested package but still originating from IMAP server
        }
        if (imapFolder != null) {
            Store store = imapFolder.getStore();
            if (store != null && store.isConnected()) {
                // closing store closes and its folders
                log.debug("Closing store (" + store.toString() + ") and associated folders");
                store.close();
            }
        }
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:25,代码来源:MimePackage.java

示例3: isMailReceivedBySubject

import javax.mail.Store; //导入依赖的package包/类
/**
 * Check mail folder for an email using subject.
 *
 * @param emailSubject Email subject
 * @param folder       mail folder to check for an email
 * @param protocol     protocol used to connect to the server
 * @return whether mail received or not
 * @throws MessagingException if we're unable to connect to the store
 */
private static boolean isMailReceivedBySubject(String emailSubject, String folder, String protocol,
        GreenMailUser user) throws MessagingException {
    boolean emailReceived = false;
    Folder mailFolder;
    Store store = getConnection(user, protocol);
    try {
        mailFolder = store.getFolder(folder);
        mailFolder.open(Folder.READ_WRITE);
        SearchTerm searchTerm = new AndTerm(new SubjectTerm(emailSubject), new BodyTerm(emailSubject));
        Message[] messages = mailFolder.search(searchTerm);
        for (Message message : messages) {
            if (message.getSubject().contains(emailSubject)) {
                log.info("Found the Email with Subject : " + emailSubject);
                emailReceived = true;
                break;
            }
        }
    } finally {
        if (store != null) {
            store.close();
        }
    }
    return emailReceived;
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:34,代码来源:GreenMailServer.java

示例4: prepareMailbox

import javax.mail.Store; //导入依赖的package包/类
private void prepareMailbox() throws Exception {
    // connect to mailbox
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("pop3");
    store.connect("localhost", 25, "jones", "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();

    // inserts 5 new messages
    Message[] messages = new Message[5];
    for (int i = 0; i < 5; i++) {
        messages[i] = new MimeMessage(sender.getSession());
        messages[i].setHeader("Message-ID", "" + i);
        messages[i].setText("Message " + i);
    }
    folder.appendMessages(messages);
    folder.close(true);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:MailFetchSizeTest.java

示例5: initInbox

import javax.mail.Store; //导入依赖的package包/类
private static void initInbox() {
	try {
		System.out.println("Inbox initiating...");

        Properties props = new Properties();
        props.setProperty(MAIL_STORE_PROTOCOL_KEY, mailConfig.getProperty(MAIL_STORE_PROTOCOL_KEY));

        // Used gmail with lesser secure authentication (https://www.google.com/settings/security/lesssecureapps)
        // For a full access I should implement OAuth2 for ArdulinkMail (https://java.net/projects/javamail/pages/OAuth2)
        
        Session session = Session.getInstance(props, null);
		Store store = session.getStore();
		System.out.println(mailConfig.getProperty(MAIL_HOST_KEY) + " " + mailConfig.getProperty(MAIL_USER_KEY) + " " + mailConfig.getProperty(MAIL_PASSWORD_KEY));
        store.connect(mailConfig.getProperty(MAIL_HOST_KEY), mailConfig.getProperty(MAIL_USER_KEY), mailConfig.getProperty(MAIL_PASSWORD_KEY));
        
        // clearDefault(store.getDefaultFolder()); // With GMAIL it doesn't work since "all messages" cannot be cleared.
        clearMainFolder(store.getFolder("INBOX"));
        
        inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_WRITE);
		System.out.println("Inbox initiated");
	} catch (Exception e) {
		throw new IllegalStateException("Error initiating inbox. Exiting...");
	}
}
 
开发者ID:Ardulink,项目名称:Ardulink-1,代码行数:26,代码来源:MailListener.java

示例6: reconnectStoreIfClosed

import javax.mail.Store; //导入依赖的package包/类
/**
 * Reconnects if connection is closed.
 * <b>Note</b>Internal method
 * @return true if store re-connection is performed and this means that close should be closed after the work is done
 * @throws MessagingException
 */
public boolean reconnectStoreIfClosed() throws MessagingException {

    boolean storeReconnected = false;

    // the folder is empty when the message is not loaded from IMAP server, but from a file
    Folder imapFolder = message.getFolder();
    if (imapFolder == null) {
        imapFolder = this.partOfImapFolder;
    } else {
        partOfImapFolder = imapFolder; // keep reference
    }
    if (imapFolder != null) {
        Store store = imapFolder.getStore();
        if (store != null) {
            if (!store.isConnected()) {
                log.debug("Reconnecting store... ");
                store.connect();
                storeReconnected = true;
            }

            // Open folder in read-only mode
            if (!imapFolder.isOpen()) {
                log.debug("Reopening folder " + imapFolder.getFullName()
                          + " in order to get contents of mail message");
                imapFolder.open(Folder.READ_ONLY);
            }
        }
    }
    return storeReconnected;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:37,代码来源:MimePackage.java

示例7: createTestMessages

import javax.mail.Store; //导入依赖的package包/类
public void createTestMessages() {
    try {
        GreenMailUser user = greenMail.setUser(TEST_RECIP, "password");

        final String subject = GreenMailUtil.random();
        final String body = GreenMailUtil.random();
        user.deliver(createMimeMessage("[email protected]", subject, body, null));
        user.deliver(createMimeMessage("[email protected]", "Great stuff cheap!", "body", null));
        user.deliver(createMimeMessage("[email protected]", "Happening this month", "stuff", null));
        user.deliver(createMimeMessage("[email protected]", "Get certified today!", "Cheap!", null));
        user.deliver(createMimeMessage("[email protected]", "It's been a long time!", "Let's talk", null));
        user.deliver(createMimeMessage("[email protected]", "The Sound of Drums", "boom boom boom", 
                 Date.from(LocalDate.now().minusYears(2).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())));

        Session imapSession = greenMail.getImap().createSession();
        Store store = imapSession.getStore("imap");
        store.connect(TEST_RECIP, "password");
        
        Folder defaultFolder = store.getDefaultFolder();  
        Folder inbox = store.getFolder("INBOX");
        inbox.open(Folder.READ_WRITE);
        
        Folder ads = defaultFolder.getFolder("Ads");
        ads.create(Folder.HOLDS_MESSAGES);   
        
        Folder spam = defaultFolder.getFolder("Spam");
        spam.create(Folder.HOLDS_MESSAGES); 
    } catch (MessagingException ex) {
        Logger.getLogger(TestMailUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:32,代码来源:TestMailUtil.java

示例8: deleteAllEmails

import javax.mail.Store; //导入依赖的package包/类
/**
 * Delete all emails in the inbox.
 *
 * @param protocol protocol used to connect to the server
 * @throws MessagingException if we're unable to connect to the store
 */
public static void deleteAllEmails(String protocol, GreenMailUser user) throws MessagingException {
    Folder inbox = null;
    Store store = getConnection(user, protocol);
    try {
        inbox = store.getFolder(EMAIL_INBOX);
        inbox.open(Folder.READ_WRITE);
        Message[] messages = inbox.getMessages();

        for (Message message : messages) {
            message.setFlag(Flags.Flag.DELETED, true);
            log.info("Deleted email Subject : " + message.getSubject());
        }
    } finally {
        if (inbox != null) {
            inbox.close(true);
        }
        if (store != null) {
            store.close();
        }
    }
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:28,代码来源:GreenMailServer.java

示例9: isMailReceived

import javax.mail.Store; //导入依赖的package包/类
/**
 * Check whether email received by reading the emails.
 *
 * @param protocol to connect to the store
 * @param user whose mail store should be connected
 * @param subject the subject of the mail to search
 * @return
 * @throws MessagingException when unable to connect to the store
 */
public static boolean isMailReceived(String protocol, GreenMailUser user, String subject)
        throws MessagingException {
    Store store = getConnection(user, protocol);
    Folder folder = store.getFolder(EMAIL_INBOX);
    folder.open(Folder.READ_ONLY);
    boolean isReceived = false;
    Message[] messages = folder.getMessages();
    for (Message message : messages) {
        if (message.getSubject().contains(subject)) {
            log.info("Found the Email with Subject : " + subject);
            isReceived = true;
            break;
        }
    }
    return isReceived;
}
 
开发者ID:wso2,项目名称:product-ei,代码行数:26,代码来源:GreenMailServer.java

示例10: assertConnection

import javax.mail.Store; //导入依赖的package包/类
/**
 * Asserts that a connection to the given mailbox is possible.
 *
 * @param protocol
 *            The protocol.
 * @param isStartTls
 *            True, if StartTLS ist possible.
 * @param host
 *            The host.
 * @param port
 *            The port.
 * @param login
 *            The login.
 * @param password
 *            The password.
 * @param mailbox
 *            The mailbox.
 * @throws ConnectionException
 *             Exception.
 * @throws MessagingException
 *             Exception.
 */
private void assertConnection(String protocol, boolean isStartTls, String host, String port,
        String login, String password, String mailbox) throws ConnectionException,
        MessagingException {
    String propertiesProtocolPrefix = "mail." + protocol + ".";
    Properties properties = new Properties();
    properties.putAll(System.getProperties());
    properties.put(propertiesProtocolPrefix + "starttls.enable", isStartTls);
    Session session = Session.getInstance(properties);
    Store store = session.getStore(protocol);
    try {
        store.connect(host, NumberUtils.toInt(port, -1), login, password);
        Folder folder = store.getFolder(mailbox);
        if (!folder.exists()) {
            throw new FolderNotFoundException();
        }
    } finally {
        store.close();
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:42,代码来源:MailInController.java

示例11: prepareMailbox

import javax.mail.Store; //导入依赖的package包/类
private void prepareMailbox() throws Exception {
    // connect to mailbox
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("pop3");
    store.connect("localhost", 25, "bill", "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();

    // inserts 1 new message
    Message[] messages = new Message[1];
    messages[0] = new MimeMessage(sender.getSession());
    messages[0].setSubject("TestSubject");
    messages[0].setHeader("Message-ID", "0");
    messages[0].setText("TestText");

    folder.appendMessages(messages);
    folder.close(true);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:MailPostProcessActionTest.java

示例12: prepareMailbox

import javax.mail.Store; //导入依赖的package包/类
private void prepareMailbox() throws Exception {
    // connect to mailbox
    Mailbox.clearAll();

    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("imap");
    store.connect("localhost", 25, "claus", "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();

    // inserts two new messages
    Message[] msg = new Message[2];
    msg[0] = new MimeMessage(sender.getSession());
    msg[0].setText("Message 1");
    msg[0].setHeader("Message-ID", "0");
    msg[0].setFlag(Flags.Flag.SEEN, false);
    msg[1] = new MimeMessage(sender.getSession());
    msg[1].setText("Message 2");
    msg[0].setHeader("Message-ID", "1");
    msg[1].setFlag(Flags.Flag.SEEN, true);
    folder.appendMessages(msg);
    folder.close(true);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:MailDoNotDeleteIfProcessFailsTest.java

示例13: prepareMailbox

import javax.mail.Store; //导入依赖的package包/类
private void prepareMailbox(String user, String type) throws Exception {
    // connect to mailbox
    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore(type);
    store.connect("localhost", 25, user, "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();

    InputStream is = getClass().getResourceAsStream("/SignedMailTestCaseHurz.elm");
    Message hurzMsg = new MimeMessage(sender.getSession(), is);
    Message[] messages = new Message[] {hurzMsg};

    // insert one signed message
    folder.appendMessages(messages);
    folder.close(true);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:RawMailMessageTest.java

示例14: prepareMailbox

import javax.mail.Store; //导入依赖的package包/类
private void prepareMailbox() throws Exception {
    // connect to mailbox
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("pop3");
    store.connect("localhost", 25, "jones", "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();

    // inserts 5 new messages
    Message[] messages = new Message[5];
    for (int i = 0; i < 5; i++) {
        messages[i] = new MimeMessage(sender.getSession());
        messages[i].setText("Message " + i);
        messages[i].setHeader("Message-ID", "myuid-" + i);
    }
    folder.appendMessages(messages);
    folder.close(true);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:MailIdempotentRepositoryTest.java

示例15: prepareMailbox

import javax.mail.Store; //导入依赖的package包/类
private void prepareMailbox() throws Exception {
    // connect to mailbox
    Mailbox.clearAll();
    JavaMailSender sender = new DefaultJavaMailSender();
    Store store = sender.getSession().getStore("imap");
    store.connect("localhost", 25, "claus", "secret");
    Folder folder = store.getFolder("INBOX");
    folder.open(Folder.READ_WRITE);
    folder.expunge();

    // inserts two messages with the SEEN flag
    Message[] msg = new Message[2];
    msg[0] = new MimeMessage(sender.getSession());
    msg[0].setText("Message 1");
    msg[0].setHeader("Message-ID", "0");
    msg[0].setFlag(Flags.Flag.SEEN, true);
    msg[1] = new MimeMessage(sender.getSession());
    msg[1].setText("Message 2");
    msg[0].setHeader("Message-ID", "1");
    msg[1].setFlag(Flags.Flag.SEEN, true);
    folder.appendMessages(msg);
    folder.close(true);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:MailProcessOnlyUnseenMessagesTest.java


注:本文中的javax.mail.Store类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。