【问题标题】:How I can use IMAPS in XPages如何在 XPage 中使用 IMAPS
【发布时间】:2014-02-01 21:49:37
【问题描述】:

我想构建一个 XPage 来使用 JavaMail 检索电子邮件。使用 imap 提供程序连接到服务器没有问题(例如 session.getStore("imap"))。但现在我想通过 imaps (session.getStore("imaps")) 连接到邮件服务器。我得到的只是一个例外“NoSouchProvider”。

如果我看一下注册会话的提供商,只有 POP3、SMTP 和 IMAP;没有 IMAPS。

有没有办法将 IMAPS 与 XPage 一起使用?我有什么选择?

顺便说一句:Domino 服务器是 9.0。

【问题讨论】:

    标签: xpages imap


    【解决方案1】:

    我使用了使 IMAP 与 gMail 兼容的 modified classes,并使用了以下代码:

    private GmailSSLStore getStore() throws MessagingException {
        if (this.store != null) {
            return this.store;
         }
        Properties props = System.getProperties();
        props.setProperty("mail.imaps.connectiontimeout", "5000");
        props.setProperty("mail.imaps.host", "imap.gmail.com");
        props.setProperty("mail.imaps.partialfetch", "false");
        props.setProperty("mail.imaps.port", "993");
        props.setProperty("mail.imaps.timeout", "5000");
        props.setProperty("mail.mime.base64.ignoreerrors", "true");
        props.setProperty("mail.store.protocol", "gimaps");
    
        javax.mail.Session session = Session.getDefaultInstance(props, null);
        this.store = (GmailSSLStore) session.getStore("gimaps");
        this.store.connect(this.userName, this.passWord);
        // Ready for connection ;-)
        return this.store;
    }
    

    您可以修改该代码以适应您的需要。希望有帮助

    【讨论】:

    • 我会进一步尝试您的解决方案。但目前我有两个问题: 问题一:如果我在 XPage 中调用 System.getProperties() 会出现安全异常,即我不能访问这些属性。我知道我可以编辑 java.policy 但这不是我的客户的选择。那么还有其他解决方案吗?第二个问题:您的建议扩展了 JavaMail 1.4.4,但多米诺服务器使用 JavaMail 1.3。我可以简单地使用这个扩展吗?
    • 最简单的方法是将您的 Java 代码打包到 OSGi 插件中。对安全问题进行排序,您可以添加模组
    • 构建一个 OSGi 插件可能是一个解决方案。但是,如何从我的 XPage 调用此插件中的 java 类?在我的 XPage 中调用插件中的任何类都会导致“找不到类”-Exception。
    【解决方案2】:

    使用 IMAP 提供程序并要求 javamail 的 STARTTLS 属性(IIRC 它是一个属性)。

    【讨论】:

    • 我或许应该详细说明。 STARTTLS 是一个 IMAP 命令,用于开始加密直到该点的明文 IMAP 会话。 starttls 通常用作第一个命令。
    猜你喜欢
    • 2014-07-08
    • 2021-02-21
    • 1970-01-01
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 2013-05-19
    • 1970-01-01
    • 2023-03-07
    相关资源
    最近更新 更多