139邮箱java版

阅读: 评论:0

139邮箱java版

139邮箱java版

用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 = Properties();

//设置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");

Session session&#Instance(props,null);

String mailer = "send from VU java SMTP";

//设置收件人

String sendTo = "xxxx@139";

//设置抄送人

String sendCC = "";

//设置发件人

String sendFrom = "xxxx@139";

try{

SMTPTransport t = (Transport(ssl ? "smtps" : "smtp");

//与SMTP主机相连

MimeMessage msg = new MimeMessage(session);

Attachment attachment = new Attachment();

attachment.setFile(f);

//设置邮件各个字段

String subject = "smtp测试";

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

String body =        "这里有很多内容rn这里有很多内容rn这里有很多内容rn这里有很多内容rn这里有很多内容";

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

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

}

本文发布于:2024-02-04 09:02:26,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170703646154191.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:邮箱   java
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23