To do this you will need to use the functions FOpen and FRead to input the file into the email. The script below shows how this can be achieved: benchmark SilkPerformerRecorder use "WebAPI.bdh" dcluser user VUser transactions TInit : begin; TMain : 1; var sdata :string (10000); dclrand dcltrans transaction TInit begin end TInit; transaction TMain var hPop0 : number; hSmtp0 : number; nMsgNumber : number; nMsgSize : number; hFile : number; sOutput : string; Smessage : String (10000); nRead : number; begin // Open a handle to the file email.txt, which will contain the data to be //posted off in the email. FOpen(hFile, "c:\\temp\\email.txt", OPT_FILE_ACCESS_READWRITE, OPT_FILE_OPEN); write("File has been opened"); writeln; FRead(hFile, sData, 10000, nRead); WebPopConnect(hPop0, "100.19.10.21", 110); WebPopUser(hPop0, "user1"); WebPopPass(hPop0, "password"); WebPopStat(hPop0, nMsgNumber, nMsgSize); WebPopQuit(hPop0); WebPopShutdown(hPop0); WebSmtpConnect(hSmtp0, "100.19.10.21", 25); WebSmtpHello(hSmtp0, "user1"); WebSmtpMail(hSmtp0, " "); WebSmtpRecipient(hSmtp0, " "); // start sending DATA WebSmtpSendData(hSmtp0,"DATA\r\n"); // SMTP header WebSmtpSendData(hSmtp0, "From: \"user1\" \r\n" "To: \"User2\" \r\n" "Subject: Text file\r\n" "Date: Fri, 24 Jan 2003 17:09:43 -0000\r\n" "Message-ID: \r\n" "MIME-Version: 1.0\r\n" "Content-Type: multipart/mixed;\r\n" "\tboundary=\"----=_NextPart_000_0000_01C2C3CB.63CFB7D0\"\r\n" "X-Priority: 3 (Normal)\r\n" "X-MSMail-Priority: Normal\r\n" "X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0)\r\n" "Importance: Normal\r\n" "X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200\r\n" "\r\n"); // SMTP body writeln (sdata); WebSmtpSendData(hSmtp0,"This is a multi-part message in MIME format.\r\n" "\r\n" "------=_NextPart_000_0000_01C2C3CB.63CFB7D0\r\n" "Content-Type: text/plain;\r\n" "\tcharset=\"iso-8859-1\"\r\n" "Content-Transfer-Encoding: 7bit\r\n" "\r\n" "enclosed\r\n" "\r\n" "------=_NextPart_000_0000_01C2C3CB.63CFB7D0\r\n" "Content-Type: text/plain;\r\n" "\tname=\"DiskSpace.txt\"\r\n" "Content-Transfer-Encoding: quoted-printable\r\n" "Content-Disposition: attachment;\r\n" "\tfilename=\"DiskSpace.txt\"\r\n" "\r\n" + sDATA + "\r\n" "------=_NextPart_000_0000_01C2C3CB.63CFB7D0--\r\n" "\r\n" ".\r\n"); ThinkTime(3.2); WebSmtpQuit(hSmtp0); WebSmtpShutdown(hSmtp0); ThinkTime(2.5); WebPopConnect(hPop0, "100.19.10.21", 110); WebPopUser(hPop0, "user1"); WebPopPass(hPop0, "password"); WebPopStat(hPop0, nMsgNumber, nMsgSize); WebPopQuit(hPop0); WebPopShutdown(hPop0); end TMain; Important features to note are that when inserting the variable SData (which contains the data to be sent in the email) into the function WebSmtpSendData we need to ensure that both the header and footer of the email are enclosed also. To have the loadtest use a different file each time we could randomize the files that the FOpen will create a handle to and the FRead function reads in.
↧