zoukankan      html  css  js  c++  java
  • 用LoadRunner测试139邮箱的脚本,用JavaVUser

    用LoadRunner测试139邮箱的脚本,用JavaVUser编写java脚本调用mail包发送邮件,包括附件:

    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();

                //设置SMTP主机地址

                props.put("mail.smtp.host", " 123.125.50.133");

                //设置SMTP端口号,465是ssl,25是非ssl端口

                props.put("mail.smtp.port",ssl ? "465" : "25");

                //设置SMTP用户名

                props.put("mail.smtp.user","xxxx@139.com");

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

                String mailer = "send from VU java SMTP";

                //设置收件人

                String sendTo = "xxxx@139.com";

                //设置抄送人

                String sendCC = "";

               

                //设置发件人

                String sendFrom = "xxxx@139.com";

                try{

                  SMTPTransport t = (SMTPTransport)session.getTransport(ssl ? "smtps" : "smtp");

                  //与SMTP主机相连

                  t.connect("123.125.50.133","xxxx@139.com","xxx");

                  MimeMessage msg = new MimeMessage(session);

                  Attachment attachment = new Attachment();

                  attachment.setFile(f);

                 

                  //设置邮件各个字段

                  String subject = "smtp测试";

                  String personalName = "LR性能测试用户";

                  String body =        "这里有很多内容\r\n这里有很多内容\r\n这里有很多内容\r\n这里有很多内容\r\n这里有很多内容";

                  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,to);

                  msg.setSubject(subject,charset);

                  msg.setText(body,charset);

                  msg.setSentDate(new Date());

                  //发送邮件

                  t.sendMessage(msg, msg.getAllRecipients());

                    t.close();

                }

               catch (Exception e){

                  e.printStackTrace();

               }

               finally{

               }

          

               return 0;

           }//end of action

             /**

         * 添加附件

         *

         * @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");

           }

           

       }

        /**

         * 添加附件

         *

         * @param filePath

         * @throws FileNotFoundException

         */

           public int end() {

                  return 0;

           }//end of end

    }

  • 相关阅读:
    安装node.js webkit环境[一]
    wpf 窗口最小化后,触发某事件弹出最小化窗口并置顶
    c# 旋转图片 无GDI+一般性错误
    类库里面添加日志记录 log4net
    string转xml
    DES c#加密后java解密
    使用排序字典排序
    怎么让一段xml被识别为字符串
    新装iis 页面503错误 DefaultAppPool停止解决方案
    hession
  • 原文地址:https://www.cnblogs.com/preftest/p/2028641.html
Copyright © 2011-2022 走看看