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


Java Store.getFolder方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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,代码来源:MailIdempotentRepositoryDuplicateTest.java

示例6: 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", "" + i);
    }
    folder.appendMessages(messages);
    folder.close(true);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:MailShutdownCompleteAllTasksTest.java

示例7: 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

示例8: deleteMailsFromUserMailbox

import javax.mail.Store; //导入方法依赖的package包/类
protected void deleteMailsFromUserMailbox(final Properties props, final String folderName, final int start, final int deleteCount,
        final String user, final String password) throws MessagingException {
    final Store store = Session.getInstance(props).getStore();

    store.connect(user, password);
    checkStoreForTestConnection(store);
    final Folder f = store.getFolder(folderName);
    f.open(Folder.READ_WRITE);

    final int msgCount = f.getMessageCount();

    final Message[] m = deleteCount == -1 ? f.getMessages() : f.getMessages(start, Math.min(msgCount, deleteCount + start - 1));
    int d = 0;

    for (final Message message : m) {
        message.setFlag(Flag.DELETED, true);
        logger.info("Delete msgnum: {} with sid {}", message.getMessageNumber(), message.getSubject());
        d++;
    }

    f.close(true);
    logger.info("Deleted " + d + " messages");
    store.close();

}
 
开发者ID:salyh,项目名称:elasticsearch-imap,代码行数:26,代码来源:AbstractIMAPRiverUnitTest.java

示例9: testAllServices

import javax.mail.Store; //导入方法依赖的package包/类
@Test
public void testAllServices() throws MessagingException {
    // Send messages via SMTP and secure SMTPS
    GreenMailUtil.sendTextEmail("[email protected]", "[email protected]",
            "test1", "Test GreenMail Docker service",
            ServerSetupTest.SMTP.createCopy(bindAddress));
    GreenMailUtil.sendTextEmail("[email protected]", "[email protected]",
            "test2", "Test GreenMail Docker service",
            ServerSetupTest.SMTPS.createCopy(bindAddress));

    // IMAP
    for (ServerSetup setup : Arrays.asList(
            ServerSetupTest.IMAP.createCopy(bindAddress),
            ServerSetupTest.IMAPS.createCopy(bindAddress),
            ServerSetupTest.POP3.createCopy(bindAddress),
            ServerSetupTest.POP3S.createCopy(bindAddress))) {
        final Store store = Session.getInstance(setup.configureJavaMailSessionProperties(null, false)).getStore();
        store.connect("[email protected]", "[email protected]");
        try {
            Folder folder = store.getFolder("INBOX");
            folder.open(Folder.READ_ONLY);
            assertEquals("Can not check mails using "+store.getURLName(), 2, folder.getMessageCount());
        } finally {
            store.close();
        }
    }
}
 
开发者ID:greenmail-mail-test,项目名称:greenmail,代码行数:28,代码来源:DockerServiceIT.java

示例10: checkNewMessage

import javax.mail.Store; //导入方法依赖的package包/类
public void checkNewMessage() {
	logger.debug("check new message...");

	try {
		Session session = Session.getInstance(props, null);
		Store store = session.getStore();
		store.connect(user, password);
		Folder inbox = store.getFolder(checkFolder);
		inbox.open(Folder.READ_WRITE);
		
		for (javax.mail.Message msg : inbox.getMessages()) {
			processMail(msg);
		}
		// inbox.

	} catch (Exception mex) {
		mex.printStackTrace();
	}
}
 
开发者ID:jackhatedance,项目名称:visual-programming,代码行数:20,代码来源:EmailAgent.java

示例11: getEmail

import javax.mail.Store; //导入方法依赖的package包/类
public Mail getEmail(int mailId, MailCredentials credentials, String salt) throws MessagingException, IOException {
	Properties properties = getServerProperties(credentials.getProtocol(), credentials.getHost(),
			"" + credentials.getPort());
	Session session = Session.getDefaultInstance(properties);

	// connects to the message store
	Store store = session.getStore(credentials.getProtocol());
	store.connect(credentials.getUsername(), credentials.getPassword());

	// opens the inbox folder
	Folder folderInbox = store.getFolder("INBOX");
	folderInbox.open(Folder.READ_ONLY);

	// fetches new messages from server
	int msgnum[] = new int[] { mailId };
	Message[] messages = folderInbox.getMessages(msgnum);

	Mail mail = getMails(messages).get(0);

	// disconnect
	folderInbox.close(false);
	store.close();
	return mail;
}
 
开发者ID:HTWK-App,项目名称:Server-Application,代码行数:25,代码来源:EmailReceiver.java

示例12: changeMailStatus

import javax.mail.Store; //导入方法依赖的package包/类
public void changeMailStatus(int mailId, Flag flag, MailCredentials credentials) throws MessagingException {
	Properties properties = getServerProperties(credentials.getProtocol(), credentials.getHost(),
			"" + credentials.getPort());
	Session session = Session.getDefaultInstance(properties);

	// connects to the message store
	Store store = session.getStore(credentials.getProtocol());
	store.connect(credentials.getUsername(), credentials.getPassword());

	// opens the inbox folder
	Folder folderInbox = store.getFolder("INBOX");
	folderInbox.open(Folder.READ_WRITE);

	logger.debug("unread:" + folderInbox.getUnreadMessageCount() + ", new:" + folderInbox.getNewMessageCount());

	// fetches new messages from server
	int msgnum[] = new int[] { mailId };
	Message[] messages = folderInbox.getMessages(msgnum);

	if (messages.length == 1 && messages[0] != null) {
		messages[0].setFlag(flag, true);
	}

	folderInbox.close(false);
	store.close();
}
 
开发者ID:HTWK-App,项目名称:Server-Application,代码行数:27,代码来源:EmailReceiver.java

示例13: 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 3 messages, one with earlier, one with later sent date and one with invalid subject (not returned in search)
    Message[] messages = new Message[3];
    messages[0] = new MimeMessage(sender.getSession());
    messages[0].setText("Earlier date");
    messages[0].setHeader("Message-ID", "0");
    messages[0].setSentDate(new Date(10000));
    messages[0].setSubject("Camel");

    messages[1] = new MimeMessage(sender.getSession());
    messages[1].setText("Later date");
    messages[1].setHeader("Message-ID", "1");
    messages[1].setSentDate(new Date(20000));
    messages[1].setSubject("Camel");

    messages[2] = new MimeMessage(sender.getSession());
    messages[2].setText("Even later date");
    messages[2].setHeader("Message-ID", "2");
    messages[2].setSentDate(new Date(30000));
    messages[2].setSubject("Invalid");

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

示例14: _getEmail

import javax.mail.Store; //导入方法依赖的package包/类
public MessageWrapper _getEmail( String hostName, MessageFilter[] messageFilters, Map<String, String> propertyMap )
{
    Properties mailProps = new Properties();
    mailProps.putAll( propertyMap );

    List<Message> messageList = new ArrayList<Message>( 10 );
    MessageWrapper messageWrapper = null;

    try
    {
        Session emailSession = Session.getDefaultInstance( mailProps );
        Store store = emailSession.getStore( propertyMap.get( PROTOCOL ) );
        store.connect( hostName, propertyMap.get( USER_NAME ), propertyMap.get( PASSWORD ) );

        Folder emailFolder = store.getFolder( propertyMap.get( FOLDER_NAME ) != null ? propertyMap.get( FOLDER_NAME ) : DEFAULT_FOLDER_NAME );
        emailFolder.open( Folder.READ_WRITE );

        Message[] messages = emailFolder.getMessages();

        int messageCount = emailFolder.getMessageCount();
        if ( messageCount > MAX_MESSAGES )
            messageCount = MAX_MESSAGES;

        if ( log.isInfoEnabled() )
            log.info( "Processing " + messageCount + " messages" );

        for ( int i = 0; i < messageCount; i++ )
        {
            if ( applyFilters( messages[i], messageFilters ) )
            {
                messageList.add( messages[i] );
            }
        }

        if ( messageList.size() == 0 )
            throw new ScriptException( "Failed to find any email messages that met the criteria" );
            
        Collections.sort( messageList, new DateComparator() );

        String messageContent = null;
        String contentType = messageList.get( 0 ).getContentType();

        if ( contentType.startsWith( "text/" ) )
            messageContent = messageList.get( 0 ).getContent().toString();
        else if ( messageList.get( 0 ).isMimeType( "multipart/*" ) )
            messageContent = getTextFromMimeMultipart( (MimeMultipart) messageList.get( 0 ).getContent() );
        else
            messageContent = messageList.get( 0 ).getContent().getClass().getName();

        messageWrapper = new MessageWrapper( messageList.size(), messageList.get( 0 ).getFrom()[0].toString(), messageList.get( 0 ).getSubject(), messageContent, contentType );

        emailFolder.close( false );
        store.close();
    }
    catch ( Exception e )
    {
        e.printStackTrace();
        throw new ScriptException( "Failed to find email" );
    }

    return messageWrapper;
}
 
开发者ID:xframium,项目名称:xframium-java,代码行数:63,代码来源:DefaultReceiveEmailProvider.java

示例15: receive

import javax.mail.Store; //导入方法依赖的package包/类
/**
 * �����ʼ�
 */ 
public static void receive() throws Exception { 
    // ׼�����ӷ������ĻỰ��Ϣ 
    Properties props = new Properties(); 
    props.setProperty("mail.store.protocol", "pop3");       // �� 
    props.setProperty("mail.pop3.port", "110");             // �˿� 
    props.setProperty("mail.pop3.host", "pop3.sina.com");    // pop3������ 
     
    // ����Sessionʵ������ 
    Session session = Session.getInstance(props); 
    Store store = session.getStore("pop3"); 
    store.connect("[email protected]", "mh899821671104"); 
     
    // ����ռ��� 
    Folder folder = store.getFolder("INBOX"); 
    /* Folder.READ_ONLY��ֻ��Ȩ��
     * Folder.READ_WRITE���ɶ���д�������޸��ʼ���״̬��
     */ 
    folder.open(Folder.READ_WRITE); //���ռ��� 
     
    // ����POP3Э���޷���֪�ʼ���״̬,����getUnreadMessageCount�õ������ռ�����ʼ����� 
    System.out.println("δ���ʼ���: " + folder.getUnreadMessageCount()); 
     
    // ����POP3Э���޷���֪�ʼ���״̬,��������õ��Ľ��ʼ�ն���Ϊ0 
    System.out.println("ɾ���ʼ���: " + folder.getDeletedMessageCount()); 
    System.out.println("���ʼ�: " + folder.getNewMessageCount()); 
     
    // ����ռ����е��ʼ����� 
    System.out.println("�ʼ�����: " + folder.getMessageCount()); 
     
    // �õ��ռ����е������ʼ�,������ 
    Message[] messages = folder.getMessages(); 
    parseMessage(messages); 
     
    //�ͷ���Դ 
    folder.close(true); 
    store.close(); 
}
 
开发者ID:bjut-2014,项目名称:scada,代码行数:41,代码来源:MailUtils.java


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