Example usage for javax.mail Provider Provider

List of usage examples for javax.mail Provider Provider

Introduction

In this page you can find the example usage for javax.mail Provider Provider.

Prototype

public Provider(Type type, String protocol, String classname, String vendor, String version) 

Source Link

Document

Create a new provider of the specified type for the specified protocol.

Usage

From source file:com.sonicle.webtop.mail.MailAccount.java

public void setMailSession(Session session) {
    this.session = session;
    try {/*from   w  w  w. ja v a  2  s  .com*/
        session.setProvider(new Provider(Provider.Type.STORE, "imap", "com.sonicle.mail.imap.SonicleIMAPStore",
                "Sonicle", "1.0"));
        session.setProvider(new Provider(Provider.Type.STORE, "imaps",
                "com.sonicle.mail.imap.SonicleIMAPSSLStore", "Sonicle", "1.0"));
    } catch (NoSuchProviderException exc) {
        Service.logger.error("Cannot create mail session", exc);
    }

}

From source file:com.zotoh.maedr.device.PopIO.java

private boolean conn() {

    if (_pop == null || !_pop.isConnected())
        try {//from w  ww. j  a  v a 2  s  .  co  m
            Session session = Session.getInstance(new Properties(), null);
            Provider[] ps = session.getProviders();
            Provider sun = null;
            Store st = null;
            Folder f = null;
            String uid = isEmpty(_user) ? null : _user;
            String pwd = isEmpty(_pwd) ? null : _pwd;
            String key = ST_POP3, sn = POP3;

            closePOP();

            if (_ssl) {
                key = ST_POP3S;
                sn = POP3S;
            }

            for (int i = 0; i < ps.length; ++i) {
                if (key.equals(ps[i].getClassName())) {
                    sun = ps[i];
                    break;
                }
            }

            if (!isEmpty(_storeImpl)) {
                // this should never happen , only in testing
                sun = new Provider(Provider.Type.STORE, "pop3", _storeImpl, "test", "1.0.0");
                sn = POP3;
            }

            session.setProvider(sun);
            st = session.getStore(sn);

            if (st != null) {
                st.connect(_host, _port, uid, pwd);
                f = st.getDefaultFolder();
            }

            if (f != null) {
                f = f.getFolder("INBOX");
            }

            if (f == null || !f.exists()) {
                throw new Exception("POP3: Cannot find inbox");
            }

            _pop = st;
            _fd = f;

        } catch (Exception e) {
            tlog().warn("", e);
            closePOP();
        }

    return _pop != null && _pop.isConnected();
}