首页 > 解决方案 > 在 Apache JMeter 中发送带有多个附件的电子邮件的 GROOVY 脚本

问题描述

我正在使用 Apache JMeter 加载测试电子邮件。我尝试使用简单的 SMTP 采样器,但由于某种未知原因它失败了(无法将套接字转换为 tls)

所以我使用了一个 groovy 脚本并将其放入 JSR223 采样器中。为了实现它,我首先下载了 2 个 JAR 文件并将其添加到“lib”文件夹中。

JAR 文件是:

  1. 简单的java-mail-5.1.3.jar
  2. 电子邮件地址-rfc2822-1.1.2.jar

将这些 JAR 文件添加到 lib 文件夹后,我将以下代码放入采样器中:

import org.simplejavamail.email.Email
import org.simplejavamail.email.EmailBuilder
import org.simplejavamail.mailer.Mailer
import org.simplejavamail.mailer.MailerBuilder
import org.simplejavamail.mailer.config.TransportStrategy

Mailer mailer = MailerBuilder
        .withTransportStrategy(TransportStrategy.SMTP_TLS)
        .withSMTPServer("outlook.office365.com", 587)
        .withSMTPServerUsername("jitender.singh@outlook.com")
        .withSMTPServerPassword("*******")
       // .withProxyHost("replace with your proxy host")
       // .withProxyPort(1234) // replace with your proxy port
       // .withProxyUsername("your proxy username if needed")
       // .withProxyPassword("your proxy password if needed")
        .buildMailer()

Email email = EmailBuilder.startingBlank()
        .from("jitender.singh@outlook.com")
        .to("test@outlook.com")
        .withSubject("test subject")
        .withPlainText("test message")
        .buildEmail()

mailer.sendMail(email)

此设置有效。

我需要帮助的是修改上面的代码,以便我可以在每封电子邮件中发送 3 个附件。

有人可以帮我吗?

我正在使用 Apache JMeter 5.4.1

标签: groovysmtpjmeter-5.0jsr223

解决方案


你可以利用SMTP Sampler. 我可以根据您的要求提供所有选项,包括附加多个文件。

有关详细信息,请参阅此处:https ://www.blazemeter.com/blog/load-testing-your-email-server-how-send-and-receive-e-mails-jmeter

在此处输入图像描述


推荐阅读