import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.eviware.soapui.support.types.StringToStringMap;
import javax.mail.*;
class SendMailTLS{
public void sendMail(String statusCode){
final String username="*********@qq.com";
final String password="*********";//发送邮箱的密码,即开启smtp服务得到的授权码。注:不是QQ密码。
Properties props=new Properties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.host","smtp.qq.com");//QQ邮箱的smtp服务器地址
props.put("mail.smtp.port","25");
Session session=Session.getInstance(props,
new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(username,password);
}
});
try {
Message message=new MimeMessage(session);
message.setFrom(new InternetAddress("Ting.Zuo@edenred.com"));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("Ting.Zuo@edenred.com"));
message.setSubject("Status alert");
message.setText("The httpStatus from the last call was:"+statusCode);
Transport.send(message);
System.out.println("Done");
}catch (MessagingException e){
throw new RuntimeException(e);
}
}
}
def statusCode=context.expand('${TestSuite Name#TestCase Name#API Name#Response}');
def mailSender=new SendMailTLS();
mailSender.sendMail(statusCode);
[SoapUI]groovy实现邮件发送
最新推荐文章于 2025-06-07 11:40:51 发布