【发布时间】:2018-07-24 00:35:25
【问题描述】:
我正在尝试建立与 office365 邮箱的连接。此函数基于一个 java 示例(请参阅https://stackoverflow.com/a/28689722/2482184)。我快完成了,但我不知道如何转换原始 java 示例中的以下代码行:
Message[] messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
下面的完整功能:
<cfscript>
mailSettings = {};
mailSettings.server = "outlook.office365.com";
mailSettings.port = "993";
mailSettings.username = "xxxx";
mailSettings.password = "xxxx";
mailSettings.action = "";
mailSettings.folder = "INBOX";
mailSettings.timeout = 5000;
properties = createObject("Java","java.util.Properties");
jsession = createObject("Java","javax.mail.Session");
store = createObject("Java","javax.mail.Store");
message = CreateObject("Java", "javax.mail.Message");
properties.init();
properties.put("mail.store.protocol","imap");
properties.put("mail.from", mailSettings.username);
properties.put("mail.imap.port", mailSettings.port);
properties.put("mail.imap.connectiontimeout",mailSettings.timeout);
properties.put("mail.imap.timeout",mailSettings.timeout);
jsession = jsession.getInstance(properties);
store = jsession.getStore("imaps");
store.connect(mailSettings.server, mailSettings.username, mailSettings.password);
inbox = store.getFolder("#mailSettings.folder#");
inbox.open( inbox.READ_ONLY );
/**********
NEED HELP TO CONVERT THIS LINE BELOW TO COLDFUSION SYNTAX
---------
Message[] messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
---------
END NEED HELP
**********/
inbox.close(true);
</cfscript>
我知道有一个 cfimap 标签。我正在尝试寻找一种更快的方法来下载电子邮件。
【问题讨论】:
-
随意发布最终代码作为答案,这样更容易发现。为了速度,您尝试过 FetchProfile 吗?从我读过的一点点来看,可能会提高获取标题的速度stackoverflow.com/a/20238586/8895292
-
@Ageax 我一直在使用 Fetch 方法,但我没有正确实施此方法。在我下面的回答中,您可以看到我尝试过的内容以及 imo 应该做什么。但是该功能并没有提高速度。
-
做错了什么,错误还是别的什么?
-
@Ageax 没有错误消息。从我读到 local.java.folder.fetch(local.java.messages, local.java.profile);方法应该下载所有消息。然后输出主题 (local.java.folder.getMessage(local.settings.x).getSubject()) 不需要再次往返 office365 服务器,而是从缓存中输出数据。然而,主题不是从缓存中检索到的,而是从 office365 服务器下载的(使用网络嗅探器确认)。
-
FetchProfile 是可选的,因此并不总是受支持。不要认为您需要“folder.getMessage(local.settings.x)”。如果我理解正确, fetch(...) 已经填充了消息数组,所以只需在每个元素上调用 getSubject() 即可。
标签: coldfusion