本文整理了Java中javax.mail.Store.connect()
方法的一些代码示例,展示了Store.connect()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Store.connect()
方法的具体详情如下:
包路径:javax.mail.Store
类名称:Store
方法名:connect
暂无
代码示例来源:origin: stackoverflow.com
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);
}
代码示例来源:origin: stackoverflow.com
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());
代码示例来源:origin: stackoverflow.com
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();
代码示例来源:origin: apache/usergrid
public Store connect( Session session ) throws MessagingException {
logger.info( "getting the session for accessing email." );
Store store = session.getStore( "imap" );
store.connect( host, user, password );
logger.info( "Connection established with IMAP server." );
return store;
}
代码示例来源:origin: igniterealtime/Openfire
Store store;
try {
store = session.getStore(useSSL ? "pop3s" : "pop3");
store.connect(host, port, username + "@" + domain, password);
store.connect(host, port, username, password);
代码示例来源:origin: stackoverflow.com
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>");
代码示例来源:origin: spring-projects/spring-integration
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();
}
}
代码示例来源:origin: com.sun.mail/javax.mail
throws MessagingException {
Store store = getStore(url);
store.connect();
return store.getFolder(url);
代码示例来源:origin: camunda/camunda-bpm-platform
throws MessagingException {
Store store = getStore(url);
store.connect();
return store.getFolder(url);
代码示例来源:origin: camunda/camunda-bpm-platform
final Store store = session.getStore("pop3");
store.connect(this.popHost, this.popUsername, this.popPassword);
代码示例来源:origin: spring-projects/spring-integration
@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();
}
代码示例来源:origin: webx/citrus
/** 连接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);
}
}
}
代码示例来源:origin: webx/citrus
/** 连接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);
}
}
}
代码示例来源:origin: opencredo/test-automation-quickstart
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;
}
代码示例来源:origin: stackoverflow.com
// 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();`
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: stackoverflow.com
Properties prop = new Properties();
//Use SSL
prop.setProperty("mail.smtp.ssl.enable",true);
Session session = Session.getInstance(prop);
Store store = session.getStore("imaps");
store.connect(hostname,username, password);
代码示例来源:origin: stackoverflow.com
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
// Put all other Properties here
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", "<username>@gmail.com", "<password>");
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: stackoverflow.com
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;
}
内容来源于网络,如有侵权,请联系作者删除!