本文整理匯總了Java中javax.mail.Session.getStore方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.getStore方法的具體用法?Java Session.getStore怎麽用?Java Session.getStore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.Session
的用法示例。
在下文中一共展示了Session.getStore方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getEmail
import javax.mail.Session; //導入方法依賴的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();
}
示例2: createTestMessages
import javax.mail.Session; //導入方法依賴的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);
}
}
示例3: getStore
import javax.mail.Session; //導入方法依賴的package包/類
private Store getStore() throws MessagingException {
if (store == null) {
// This is the JavaMail session.
Session session;
// Initialize JavaMail session.
session = Session.getDefaultInstance(new Properties(), null);
// Connect to e-mail server
store = session.getStore(mailProviderType);
store.connect(mailServer, mailUser, mailPassword);
}
return store;
}
示例4: login
import javax.mail.Session; //導入方法依賴的package包/類
/**
* Process login. Connect to server and move to folder display page.
*/
public String login()
{
try
{
// login to the IMAP server
Properties props = new Properties();
Session session = Session.getInstance(props, null);
Store store = session.getStore("imap");
store.connect(_server, _username, _password);
setStore(store);
setRootFolders(FolderData.toFolderData(this, store.getDefaultFolder().list()));
// TODO: Add logged in indicator to restrict access
_gotoFolder(null);
// Set up the user's preferences; in a real app, these would
// be persisted somewhere.
PreferencesData preferences = new PreferencesData();
setPreferences(preferences);
}
// catch all exceptions and report them as errors
catch (Exception e)
{
FacesMessage errorMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,
e.getMessage(), null);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, errorMessage);
return null;
}
return "success";
}
示例5: getImapSession
import javax.mail.Session; //導入方法依賴的package包/類
private void getImapSession() throws MessagingException, NoSuchProviderException {
Properties props = new Properties();
props.put("mail.imap.ssl.trust", "*");
props.put("mail.imaps.ssl.trust", "*");
props.setProperty("mail.imap.starttls.enable", Boolean.toString(account.isUseSsl()));
Session session = Session.getInstance(props, null);
store = session.getStore(account.isUseSsl() ? "imaps" : "imap");
store.connect(account.getServerName(), account.getUserName(), account.getPassword());
}