我尝试通过webdriver sampler中的jmeter发送邮件,但它使我陷入错误下方,但是代码在Eclipse Java上正常工作。 代码-
final String username = "xyz@abc.com"; // like yourname@outlook.com
final String password = "ABC@123"; // password here
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp-mail.outlook.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
// @Override
PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
session.setDebug(true);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("PQS@abc.com")); // like inzi769@gmail.com
message.setSubject("Test");
message.setText("HI you have done sending mail with outlook");
Transport.send(message);
WDS.log.info("Done");
}
错误- 遇到“(道具,新的javax.mail。Authenticator(){PasswordAuthentication getPasswordAuthentication(“
答案 0 :(得分:0)
确保从“语言”下拉列表中选择groovy
当您选择java
时,它不是真正的Java,而是Beanshell,其语法略有不同,通常与is not recommended for using since JMeter 3.1
为什么不使用SMTP Sampler发送电子邮件?这样会更快,更容易。请参阅Load Testing Your Email Server: How to Send and Receive E-mails with JMeter文章,以获取有关配置和使用情况的全面信息。