use of javax.mail.Store in project xwiki-platform by xwiki.
the class MailPluginApi method getMail.
public Message[] getMail(String provider, String server, String user, String password) throws MessagingException {
// Get a session. Use a blank Properties object.
Session session = Session.getInstance(new Properties());
// Get a Store object
Store store = session.getStore(provider);
store.connect(server, user, password);
try {
// Get "INBOX"
Folder fldr = store.getFolder("INBOX");
fldr.open(Folder.READ_ONLY);
return fldr.getMessages();
} finally {
store.close();
}
}
use of javax.mail.Store in project data-transfer-project by google.
the class ImapMailHelper method getFolderContents.
public MailModelWrapper getFolderContents(String host, String account, String password, @Nullable String folderName, PaginationInformation paginationInformation) throws MessagingException, IOException {
Properties props = createProperties(host, account, debug);
Session session = Session.getInstance(props);
Store store = session.getStore(PROTOCOL);
log("getFolderContents connecting to store");
try {
store.connect(host, account, password);
} catch (MessagingException e) {
log("Exception connecting to: %s, error: %s", host, e.getMessage());
throw e;
}
// If no folder specified, return the default folder
if (folderName == null) {
log("getMessages from default folder");
Folder defaultFolder;
try {
defaultFolder = store.getDefaultFolder();
} catch (MessagingException e) {
log("Exception getting default folder: %s", e.getMessage());
throw e;
}
return getMessages(host, account, password, defaultFolder, false, paginationInformation);
}
log("getMessages for specific folder: %s", folderName);
// Fetch the contents of the specified folder
Folder folder = store.getFolder(folderName);
if (folder == null || !folder.exists()) {
throw new IOException("Folder not found, name: " + folderName);
}
return getMessages(host, account, password, folder, true, paginationInformation);
}
use of javax.mail.Store in project syncope by apache.
the class AbstractNotificationTaskITCase method verifyMail.
protected boolean verifyMail(final String sender, final String subject, final String mailAddress) throws Exception {
LOG.info("Waiting for notification to be sent...");
greenMail.waitForIncomingEmail(1);
boolean found = false;
Session session = Session.getDefaultInstance(System.getProperties());
Store store = session.getStore("pop3");
store.connect(POP3_HOST, POP3_PORT, mailAddress, mailAddress);
Folder inbox = store.getFolder("INBOX");
assertNotNull(inbox);
inbox.open(Folder.READ_WRITE);
Message[] messages = inbox.getMessages();
for (Message message : messages) {
if (sender.equals(message.getFrom()[0].toString()) && subject.equals(message.getSubject())) {
found = true;
message.setFlag(Flags.Flag.DELETED, true);
}
}
inbox.close(true);
store.close();
return found;
}
use of javax.mail.Store in project ofbiz-framework by apache.
the class JavaMailContainer method start.
/**
* Start the container
*
* @return true if server started
* @throws org.apache.ofbiz.base.container.ContainerException
*/
@Override
public boolean start() throws ContainerException {
ContainerConfig.Configuration cfg = ContainerConfig.getConfiguration(name, configFile);
String dispatcherName = ContainerConfig.getPropertyValue(cfg, "dispatcher-name", "JavaMailDispatcher");
String delegatorName = ContainerConfig.getPropertyValue(cfg, "delegator-name", "default");
this.deleteMail = "true".equals(ContainerConfig.getPropertyValue(cfg, "delete-mail", "false"));
this.delegator = DelegatorFactory.getDelegator(delegatorName);
this.dispatcher = ServiceContainer.getLocalDispatcher(dispatcherName, delegator);
this.timerDelay = ContainerConfig.getPropertyValue(cfg, "poll-delay", 300000);
// maximum size in bytes
this.maxSize = ContainerConfig.getPropertyValue(cfg, "maxSize", 1000000);
// load the userLogin object
String runAsUser = ContainerConfig.getPropertyValue(cfg, "run-as-user", "system");
try {
this.userLogin = EntityQuery.use(delegator).from("UserLogin").where("userLoginId", runAsUser).queryOne();
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to load run-as-user UserLogin; cannot start container", module);
return false;
}
// load the MCA configuration
ServiceMcaUtil.readConfig();
// load the listeners
List<ContainerConfig.Configuration.Property> configs = cfg.getPropertiesWithValue("store-listener");
for (ContainerConfig.Configuration.Property prop : configs) {
Session session = this.makeSession(prop);
Store store = this.getStore(session);
stores.put(store, session);
store.addStoreListener(new LoggingStoreListener());
}
// start the polling timer
if (stores != null) {
pollTimer.scheduleAtFixedRate(new PollerTask(dispatcher, userLogin), timerDelay, timerDelay, TimeUnit.MILLISECONDS);
} else {
Debug.logWarning("No JavaMail Store(s) configured; poller disabled.", module);
}
return true;
}
use of javax.mail.Store in project ofbiz-framework by apache.
the class JavaMailContainer method getStore.
protected Store getStore(Session session) throws ContainerException {
// create the store object
Store store;
try {
store = session.getStore();
} catch (NoSuchProviderException e) {
throw new ContainerException(e);
}
// re-write the URLName including the password for this store
if (store != null && store.getURLName() != null) {
URLName urlName = this.updateUrlName(store.getURLName(), session.getProperties());
if (Debug.verboseOn()) {
Debug.logVerbose("URLName - " + urlName.toString(), module);
}
try {
store = session.getStore(urlName);
} catch (NoSuchProviderException e) {
throw new ContainerException(e);
}
}
if (store == null) {
throw new ContainerException("No store configured!");
}
// test the store
try {
store.connect();
store.close();
} catch (MessagingException e) {
Debug.logError("Unable to connect to mail store : " + store.getURLName().toString() + " : " + e.getMessage(), module);
}
return store;
}
Aggregations