Refine search
Properties props = System.getProperties(); props.setProperty("mail.store.protocol", "imaps"); try { Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("imaps"); store.connect("imap.gmail.com", "<username>@gmail.com", "<password>"); ... } catch (NoSuchProviderException e) { e.printStackTrace(); System.exit(1); } catch (MessagingException e) { e.printStackTrace(); System.exit(2); }
Properties props = System.getProperties(); props.setProperty("mail.store.protocol", "imaps"); Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("imaps"); store.connect("imap.gmail.com", "YOURMAILID@gmail.com", "UR_P@ZZWRD"); System.out.println(store); Folder[] f = store.getDefaultFolder().list(); for(Folder fd:f) System.out.println(">> "+fd.getName());
Properties props = new Properties(); //IMAPS protocol props.setProperty(“mail.store.protocol”, “imaps”); //Set host address props.setProperty(“mail.imaps.host”, imaps.gmail.com); //Set specified port props.setProperty(“mail.imaps.port”, “993″); //Using SSL props.setProperty(“mail.imaps.socketFactory.class”, “javax.net.ssl.SSLSocketFactory”); props.setProperty(“mail.imaps.socketFactory.fallback”, “false”); //Setting IMAP session Session imapSession = Session.getInstance(props); Store store = imapSession.getStore(“imaps”); //Connect to server by sending username and password. //Example mailServer = imap.gmail.com, username = abc, password = abc store.connect(mailServer, account.username, account.password); //Get all mails in Inbox Forlder inbox = store.getFolder(“Inbox”); inbox.open(Folder.READ_ONLY); //Return result to array of message Message[] result = inbox.getMessages();
Properties props = System.getProperties(); props.setProperty("mail.store.protocol", "imaps"); props.setProperty("mail.imaps.partialfetch", "false"); Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("imaps"); store.connect("imap.gmail.com", "<username>","<password>");
private void connectStoreIfNecessary() throws MessagingException { if (this.store == null) { if (this.url != null) { this.store = this.session.getStore(this.url); } else if (this.protocol != null) { this.store = this.session.getStore(this.protocol); } else { this.store = this.session.getStore(); } } if (!this.store.isConnected()) { if (this.logger.isDebugEnabled()) { this.logger.debug("connecting to store [" + this.store.getURLName() + "]"); } this.store.connect(); } }
@Test public void testStoreConnect() throws Exception { AbstractMailReceiver receiver = new AbstractMailReceiver() { @Override protected Message[] searchForNewMessages() throws MessagingException { return null; } }; Properties props = new Properties(); Session session = Session.getInstance(props); receiver.setSession(session); receiver.setProtocol("imap"); Store store = session.getStore("imap"); store = spy(store); new DirectFieldAccessor(receiver).setPropertyValue("store", store); when(store.isConnected()).thenReturn(false); Folder folder = mock(Folder.class); when(folder.exists()).thenReturn(true); when(folder.isOpen()).thenReturn(false); doReturn(folder).when(store).getFolder((URLName) null); doNothing().when(store).connect(); receiver.openFolder(); receiver.openFolder(); verify(store, times(2)).connect(); }
/** 连接mail服务器。 */ @Override public void connect() throws MailException { if (!isConnected()) { try { store = getSession().getStore(getProtocol()); store.connect(getHost(), getPort(), getUser(), getPassword()); if (getHandler() != null) { getHandler().prepareConnection(store); } } catch (NoSuchProviderException e) { store = null; throw new MailException("Could not find a provider of " + getProtocol() + " protocol", e); } catch (MessagingException me) { store = null; throw new MailException("Could not connect to the store", me); } } }
/** 连接mail服务器。 */ @Override public void connect() throws MailException { if (!isConnected()) { try { store = getSession().getStore(getProtocol()); store.connect(getHost(), getPort(), getUser(), getPassword()); if (getHandler() != null) { getHandler().prepareConnection(store); } } catch (NoSuchProviderException e) { store = null; throw new MailException("Could not find a provider of " + getProtocol() + " protocol", e); } catch (MessagingException me) { store = null; throw new MailException("Could not connect to the store", me); } } }
public EmailAdaptor connect() { try { store = session.getStore(IMAP_PROTOCOL); store.connect(IMAP_HOST, this.emailAddress, this.password); } catch (Exception e) { throw new RuntimeException("Unable to connect with provided email account credentials (" + this.emailAddress + ". Please check email properties supplied and try again"); } return this; }
// fetch the e-mail via imap using javax.mail .. // Hint: Create session via GreenMailUtil Session session = GreenMailUtil.getSession(ServerSetupTest.IMAP); // Use configured host address instead of supplying a URLName urlName = new URLName("imap", ServerSetupTest.IMAP.getBindAddress(), ServerSetupTest.IMAP.getPort(), null, user.getLogin(), user.getPassword()); Store store = session.getStore(urlName); store.connect();`
String host = "pop3.live.com"; String username = "laqetqetqet@hotmail.com"; String password = "rqetqetq"; Properties pop3Props = new Properties(); pop3Props.setProperty("mail.pop3s.port", "995"); Session session = Session.getInstance(pop3Props, null); Store store = session.getStore("pop3s"); store.connect(host, 995, username, password);
Properties props = new Properties(); props.put("mail.imap.ssl.enable", "true"); // required for Gmail props.put("mail.imap.auth.mechanisms", "XOAUTH2"); Session session = Session.getInstance(props); Store store = session.getStore("imap"); store.connect("imap.gmail.com", username, oauth2_access_token);
public class MailService { public Store connect(String protocol, String host, String username, String password) throws MessagingException{ Properties props = new Properties(); props.setProperty("mail.store.protocol", "imap"); //props.put("mail.pop3.host", host); //props.put("mail.pop3.port", port); //props.put("mail.pop3.starttls.enable", "true"); Session session = Session.getInstance(props); //session.setDebug(true); Store store = session.getStore(protocol); store.connect(host, username, password); return store; }