soapUI 读取邮件内容
来源:互联网 发布:专业非编软件 编辑:程序博客网 时间:2024/05/02 07:26
tip: 不会用groovy, 所以先用java写好,spring 下载个groovy插件,可以直接convert to groovy
import java.io.InputStreamReader;
import java.util.Properties;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.String;
import java.util.regex.Pattern;
import java.util.regex.*;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.Part;
// 连接pop3服务器的主机名、协议、用户名、密码
String host = "owa.morningstar.com";
String protocol = "pop3";
String user = "msdomain1\\******";
String pwd = "*********";
String contentSubject = "Regarding area"; // 邮件标题包含关键字
int flag=1;
// 创建一个有具体连接信息的Properties对象
Properties props = new Properties();
props.setProperty("mail.store.protocol", protocol);
props.setProperty("mail.pop3.host", host);
// 使用Properties对象获得Session对象
Session session = Session.getInstance(props);
session.setDebug(true);
// 利用Session对象获得Store对象,并连接pop3服务器
Store store = session.getStore(protocol);
store.connect(host, user, pwd);
// 获得邮箱内的邮件夹Folder对象,以"只读"打开
Folder folder = store.getFolder("inbox"); // for POP3 just can open the inbox folder
folder.open(Folder.READ_ONLY);
// 获得邮件夹Folder内的所有邮件Message对象
Message [] messages = folder.getMessages();
int mailCounts = messages.length;
//search form the newest
for(int i = mailCounts-1; i > mailCounts-10; i--) {
StringBuffer bodytext = new StringBuffer(); //存放邮件内容的StringBuffer对象
String subject = messages[i].getSubject();
String contentType = messages[i].getContentType(); // check the contenttype , here is the text, if the type is other ,maybe not work
if (subject.contains(contentSubject)){
bodytext.append((String)messages[i].getContent());
// get the quick base number form the email contentString body = bodytext;
String[] QBsplit = body.split("<br>Quickbase");
String QBNumber =QBsplit[1].substring(1,13);
// assert the quick base number is as expected Quickbase Ticket:[0-9]{5}
Pattern p = Pattern.compile("Ticket:[0-9]{5}");
Matcher m = p.matcher(QBNumber);
boolean b =m.matches();
if(b){
log.info "The Quicktake number is created successfully";
}
// if there are more than one same email ,just get the newest one
flag=flag+1;
if(flag==2){
break;
}
else{
log.info "The Quicktake number is created Failed" ;
}
}
}
folder.close(false);
store.close();
如果需要在下一个step用到, 可以save到project 的属性里
testRunner.testCase.testSuite.project.setPropertyValue("urlPWD",urlPWD );
0 0
- soapUI 读取邮件内容
- python3读取解析邮件内容
- c#实现outlook2003邮件内容读取
- soapui的测试内容体
- SoapUI 读取Response节点值
- java读取邮件时,邮件含有正文跟附件的时候,读取不到正文内容
- SoapUI 收邮件代码 (修改版)
- asp.net 实现发送邮件(根据国家读取对应国家语言的邮件内容)
- Nao机器人学习笔记:Nao机器人接收邮件并读取邮件内容
- 读取分析邮件(eml)内容的类。可读头/内容/附件
- Soapui
- SoapUI
- soapUi
- SoapUI
- SoaPUI
- soapui
- SOAPUI
- python实现读取本地多个TXT文件内容并发送邮件
- js function 传递汉字错误
- Nginx安装部署
- 【匈牙利算法】【二分图匹配】【转载】趣写算法系列之--匈牙利算法
- 【Ukraine】Bishops(棋盘上点的四个方向标记黑块,求最后白块数)
- 11.27JAVA序列化及克隆技术
- soapUI 读取邮件内容
- IOS版AdMob集成KeyMob广告教程
- 电脑无法开机一直滴滴响
- 【window10+vs2013+opencv3.0+cuda7.5安装与配置】
- Git 删除远程仓库文件
- 静态路由(静态汇总路由,静态默认路由,负载均衡,浮动静态路由)介绍
- 判断是否是手机号和email的方法
- 使用/proc 调试
- Java NIO (十一) Pipe