當前位置: 首頁>>代碼示例>>Java>>正文


Java Store.connect方法代碼示例

本文整理匯總了Java中javax.mail.Store.connect方法的典型用法代碼示例。如果您正苦於以下問題:Java Store.connect方法的具體用法?Java Store.connect怎麽用?Java Store.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.Store的用法示例。


在下文中一共展示了Store.connect方法的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: 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

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

示例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].setText("Message " + i);
        messages[i].setHeader("Message-ID", "myuid-" + i);
    }
    folder.appendMessages(messages);
    folder.close(true);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:21,代碼來源:MailIdempotentRepositoryTest.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].setHeader("Message-ID", "" + i);
        messages[i].setText("Message " + i);
    }
    folder.appendMessages(messages);
    folder.close(true);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:21,代碼來源:MailCopyToTest.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("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

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

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

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

示例10: checkInbox

import javax.mail.Store; //導入方法依賴的package包/類
public void checkInbox(int mode) throws MessagingException, IOException {
	if (mode == 0) {
		return;
	}
	boolean show = (mode & MailClient.SHOW_MESSAGES) > 0;
	boolean clear = (mode & MailClient.CLEAR_MESSAGES) > 0;
	String action = (show ? "Show" : "") + (show && clear ? " and " : "") + (clear ? "Clear" : "");
	System.out.println(action + " INBOX for " + from);
	Store store = session.getStore();
	store.connect();
	Folder root = store.getDefaultFolder();
	Folder inbox = root.getFolder("inbox");
	inbox.open(Folder.READ_WRITE);
	Message[] msgs = inbox.getMessages();
	if (msgs.length == 0 && show) {
		System.out.println("No messages in inbox");
	}
	for (Message msg2 : msgs) {
		MimeMessage msg = (MimeMessage) msg2;
		if (show) {
			System.out.println("    From: " + msg.getFrom()[0]);
			System.out.println(" Subject: " + msg.getSubject());
			System.out.println(" Content: " + msg.getContent());
		}
		if (clear) {
			msg.setFlag(Flags.Flag.DELETED, true);
		}
	}
	inbox.close(true);
	store.close();
	System.out.println();
}
 
開發者ID:darciopacifico,項目名稱:omr,代碼行數:33,代碼來源:MailClient.java

示例11: checkInboxSave

import javax.mail.Store; //導入方法依賴的package包/類
public void checkInboxSave(int mode) throws MessagingException, IOException {
	
	Store store = session.getStore();
	store.connect();
	Folder root = store.getDefaultFolder();
	Folder inbox = root.getFolder("inbox");
	inbox.open(Folder.READ_WRITE);
	Message[] msgs = inbox.getMessages();
	
	for (Message msg2 : msgs) {
		
		POP3Message msg = (POP3Message) msg2;
		
		Object object = msg.getContent();
		if (object instanceof Multipart) {
			Multipart multipart = (Multipart) object;
			
			for (int i = 0, n = multipart.getCount(); i < n; i++) {
				MailClient.handlePart(multipart.getBodyPart(i));
			}
			
		}
		
		System.out.println("    From: " + msg.getFrom()[0]);
		System.out.println(" Subject: " + msg.getSubject());
		System.out.println(" Content: " + object);
	}
	inbox.close(true);
	store.close();
}
 
開發者ID:darciopacifico,項目名稱:omr,代碼行數:31,代碼來源:MailClient.java

示例12: main

import javax.mail.Store; //導入方法依賴的package包/類
public static void main(String[] args) throws MessagingException {

    String url = "https://outlook.office365.com/ews/exchange.asmx";
    Properties properties = new Properties();
    properties.setProperty("org.sourceforge.net.javamail4ews.util.Util.EnableServiceTrace", "true");
    Session session = Session.getInstance(properties);

    System.out.println("retrieving the store");
    //Get the EWS store implementation
    Store store = session.getStore("ewsstore");

    System.out.println("done");

    //Connect to the Exchange server - No port required.
    //Also connect() might be used if the session is initalized with the known mail.* properties
    System.out.println(String.format("connecting to %s", url));
    store.connect(url,
      "[email protected]",
      "p4ssw0rd");

    System.out.println(String.format("connected to %s", url));
    System.out.println(String.format("get default folder", url));
    Folder folder = store.getDefaultFolder();
    System.out.println(String.format("open default folder as read-only"));
    folder.open(Folder.READ_ONLY);
    System.out.println(String.format("done"));
    Message[] messages = folder.getMessages();
    System.out.println(String.format("there is %d messages", messages.length));

    System.out.println(messages[0].getFrom());
  }
 
開發者ID:gartcimore,項目名稱:javamail4ews,代碼行數:32,代碼來源:MailSample.java

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

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

示例15: main

import javax.mail.Store; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

		Properties props = new Properties();

		String host = "pop.mailinator.com";
		String username = "x-test-m";
		String password = "mypwdxxx";
		String provider = "pop3";

		Session session = Session.getDefaultInstance(props, null);
		Store store = session.getStore(provider);
		store.connect(host, username, password);

		Folder inbox = store.getFolder("INBOX");
		if (inbox == null) {
			System.out.println("No INBOX");
			System.exit(1);
		}
		inbox.open(Folder.READ_ONLY);

		Message[] messages = inbox.getMessages();
		for (int i = 0; i < messages.length; i++) {
			System.out.println("Message " + (i + 1));
			messages[i].writeTo(System.out);
		}
		inbox.close(false);
		store.close();

	}
 
開發者ID:qmetry,項目名稱:qaf,代碼行數:30,代碼來源:MalinatorUtil.java


注:本文中的javax.mail.Store.connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。