Use LoadRunner to test the 139 email script and javavuser

Source: Internet
Author: User

Use LoadRunner to test the 139 email script, and use javavuser to write a Java Script to call the mail package to send emails, including attachments:

Import java. util. date;

Import java. util. properties;

Import javax. Mail .*;

Import javax. Mail. Internet .*;

Import com. Sun. Mail. SMTP .*;

Public class actions

{

Public int Init (){

Return 0;

} // End of init

Public int action (){

Boolean SSL = false;

Properties props = system. getproperties ();

// Set the SMTP host address

Props. Put ("mail. SMTP. Host", "123.125.50.htm ");

// Set the SMTP port number. 465 is SSL, and 25 is non-SSL port.

Props. Put ("mail. SMTP. Port", SSL? "465": "25 ");

// Set the SMTP User Name

Props. Put ("mail. SMTP. User", "xxxx@139.com ");

Session session = session. getinstance (props, null );

String Mailer = "send from VU Java SMTP ";

// Set the recipient

String sendto = "xxxx@139.com ";

// Set CC recipients

String sendcc = "";

// Set the sender

String sendfrom = "xxxx@139.com ";

Try {

Smtptransport t = (smtptransport) Session. gettransport (SSL? "Smtps": "SMTP ");

// Connect to the SMTP host

T. Connect ("123.125.50.large", "xxxx@139.com", "XXX ");

Mimemessage MSG = new mimemessage (session );

Attachment attachment = new attachment ();

Attachment. setfile (f );

// Set various email fields

String subject = "SMTP test ";

String personalname = "LR performance test user ";

String body = "There are a lot of content here \ r \ n there are a lot of content here ";

String charset = "UTF-8 ";

String name = "sendjob. Java ";

String filepath = "C:/users/Administrator/desktop/mailsender ";

Internetaddress [] to = new internetaddress [1];

Internetaddress from = new internetaddress (sendfrom, personalname, charset );

To [0] = new internetaddress (sendto, personalname, charset );

Attachment. setname (name );

Attachments. Add (Attachment );

MSG. setfrom (from );

MSG. setrecipients (message. recipienttype. To, );

MSG. setsubject (subject, charset );

MSG. settext (body, charset );

MSG. setsentdate (new date ());

// Send an email

T. sendmessage (MSG, MSG. getallrecipients ());

T. Close ();

}

Catch (exception e ){

E. printstacktrace ();

}

Finally {

}

Return 0;

} // End of action

/**

* Add attachment

*

* @ Param name

* @ Param path

* @ Throws filenotfoundexception

*/

Public void addattachment (string name, string filepath)

Throws filenotfoundexception {

File F = new file (filepath );

If (! F. exists ()){

Throw new filenotfoundexception ("file [" + filepath + "] Not Found ");

}

}

/**

* Add attachment

*

* @ Param filepath

* @ Throws filenotfoundexception

*/

Public int end (){

Return 0;

} // End of end

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.