2017-06-18 88 views
0

最新的电子邮件,我能够从通过“邮件阅读器采样”监听使用POP3电子邮件帐户获取电子邮件。但它不检索最新的电子邮件。 是否可以使用Beanshell Sampler提取最新的电子邮件。如果是的话,如果这是可以实现的,你可以分享一下代码吗?有没有办法来从“邮件阅读器取样器”或“BeanShell的取样”

按照下面的讨论 - 看起来是不可行的。但是,想要检查这是否可以通过任何方式实现? Stackoverflow Discussion on how to fetch required email

+0

的可能的复制[测试使用先进JMeter的邮件阅读样的场景(https://stackoverflow.com/questions/25075766/testing-advanced-scenarios-using-jmeter-mail-reader-sampler) –

回答

0

你可以这样做编程方式,检查了以下方法:

根据t他JavaDoc

消息编号从1开始通过文件夹中的消息总数。

所以最后一条消息的数量始终是相同的给定文件夹中的邮件总数。

示例代码中使用POP3协议读取最后一封电子邮件

import javax.mail.Folder 
import javax.mail.Message 
import javax.mail.Session 
import javax.mail.Store 

String host = "host" 
String user = "username" 
String password = "password" 

Properties properties = System.getProperties(); 
Session session = Session.getDefaultInstance(properties) 
Store store = session.getStore("pop3") 
store.connect(host, user, password) 
Folder inbox = store.getFolder("Inbox") 
inbox.open(Folder.READ_ONLY) 

int msgCount = inbox.getMessageCount() 
Message last = inbox.getMessage(msgCount) 

//do what you need with the "last" message 
inbox.close(true) 
store.close() 

我也建议忘掉BeanShell中,每当你需要执行脚本 - 使用JSR223 ElementsGroovy language比如Groovy具有更好的性能,更多的Java兼容,它有一些很好的语言功能。有关更多详细信息,请参阅Apache Groovy - Why and How You Should Use It指南。

相关问题