希望和大家一起学习共同进步!
POP3和SMTP协议的Loadrunner脚本开发
上一篇 /
下一篇 2012-03-27 17:17:26
/ 个人分类:性能测试
LR关于POP3和STMP协议脚本的开发
1、关于开发用于邮件服务POP3和SMTP的Vuser脚本
POP3是邮局协议,及收取邮件的协议SMTP是简单邮件的传输协议,及邮件的发送协议该邮件协议的函数有用于全局会话和特定邮件会话两种例子:pop3_logon 全局登录到POP3服务器pop3_logon_ex 针对特定会话登录到POP3服务器2、使用POP3函数
每个POP3函数都以pop3前缀开头函数名
| 描述
|
pop3_logon[_ex]
| 登录到POP3服务器
|
pop3_command[_ex]
| 想POP3服务器发送命令
|
pop3_retrieve[_ex]
| 检索POP3服务器上的邮件
|
pop3_list[_ex]
| 列出POP3服务器上的邮件
|
pop3_delete[_ex]
| 删除服务器上的邮件
|
pop3_free[_ex]
| 释放POP3服务器,使其不处理命令
|
pop3_logoff[_ex]
| 从POP3服务器注销
|
·全局示例:Actions()
{ //从POP3服务器上检索五封邮件
pop3_logon("Login",
URL=pop3://xiami:my_pwd@ mail.todaychina.com",
LAST);//"Loin"为事务名称,"xiami"为用户名"totalMessages=pop3_liset("POP3",LAST);
//列出POP3服务器上所有的邮件和收取值lr_log_message ("There are %d messages.\r\n\r\n",totalMessages); //显示收取的值
pop3_retrieve("POP3","RetrieveList1:5","DeleteMail=false",LAST); //检索5封邮件,不删除
pop3_logoff ();//注销POP3服务器return 0;
}·特定会话的示例(使用Foxmail进行收取):/*-------------------------------------------------------------------
Script. Title
:
Script. Description :
Recorder Version
: 1435------------------------------------------------------------------ */Actions(){pop31 = 0;
pop3_logon_ex(&pop31, "Pop3Logon",
"URL=pop3:// xiami:my_pwd@mail.todaychina.com",
LAST);
pop3_command_ex(&pop31, "Pop3Command",
"Command=STAT",
LAST);
pop3_list_ex(&pop31, "Pop3List",
LAST);
pop3_retrieve_ex(&pop31, "RetrieveMail",
"RetrieveList=675",
"DeleteMail=No",
LAST);
pop3_logoff_ex(&pop31);
pop3_free_ex(&pop31);
return 0;}3、使用SMTP函数
函数名
| 描述
|
smtp_logon[_ex]
| 登录到SMTP服务器
|
smtp_translate[_ex]
| 转换SMTP消息
|
smtp_send_mail[_ex]
| 发送SMTP消息
|
smtp_free[_ex]
| 释放SMTP服务器,使其不处理命令
|
smtp_logout[_ex]
| 从SMTP服务器注销
|
·全局示例:Actions(){ //通过SMTP服务器发送一份邮件
smtp_logon("Logon",
"URL=smtp",
"CommonName=Stmp Test User 0001",
NULL);
smtp_send_mail ("SendMail",
"To=user002",
"Subject=MIC Stmp:Sample Test",
"MAILOPTIONS",
"X-Priority:3",
"X-MSMail-Priority:Medium",
"X-Mailer:Foxmail Foxmail 6, 13, 102, 15 [cn]",
"X-MimeOLE:By Foxmail Foxmail 6, 13, 102, 15 [cn]",
"MAILADTA",
"Message Text="
"Content=Type:text/plain;\r\n"
"\tcharse=\"iso-8859-1\"\r\n"
"Test, \r\n"
"MessageBlob=16384",
NULL);
smtp_logout();
return 0;}·特定会话的示例(使用Foxmail进行收取):/*-------------------------------------------------------------------
Script. Title
:
Script. Description :
Recorder Version
: 1435------------------------------------------------------------------ */Action(){
smtp1 = 0;
smtp_logon_ex(&smtp1, "SmtpLogon",
"URL=smtp://mail.todaychina.com",
"LogonUser=xiami",
"LogonPass=my_pwd",
"CommonName=LoadRunnerUser",
LAST);
smtp_send_mail_ex(&smtp1, "SendMail",
"To=xiami@todaychina.com",
"From=<xiami@todaychina.com>",
"Subject=test",
"ContentType=multipart/related;",
MAILOPTIONS,
"From: \"xiami\" <xiami@todaychina.com>",
"To: \"xiami\" <xiami@todaychina.com>",
"X-mailer: Foxmail 6, 13, 102, 15 [cn]",
MAILDATA,
"AttachRawFile=mailnote1_01.dat",
"AttachRawFile=mailnote1_02.dat",
LAST);
smtp_logout_ex(&smtp1);smtp_free_ex(&smtp1);return 0;}
收藏
举报
TAG: