JMeter:如何通过 SMTP 采样器发送格式化文本

JMeter: how to send formatted text via SMPT sampler

有没有办法通过 JMeter SMTP 采样器发送带有 links 的格式化文本?

场景: 我需要发送一封电子邮件,其中一个词例如我的“Instagram”将在我的 Instagram 页面上显示 link。

选项 1: 在 Gmail 中创建这样的电子邮件,将其发送给自己,然后将其下载为 .eml 文件并使用 SMTP 采样器中的“发送 .eml”选项发送。

但是,我的问题是这些 links 应该被更改,并且在发送每封新电子邮件时会导致不同的 instagram 页面,因此我需要将其作为 CSV 文件中的变量传递。这似乎无法通过 .eml 文件实现,因为它需要在每次请求之前进行修改。除非有办法吗?

选项 2(首选): 不知何故,我需要在 SMTP 采样器的“消息正文”中格式化文本。我已尝试 copy/paste 来自“原始”.eml 文件的相同样式和标签,但它始终以纯文本形式发送,Gmail 不会在客户端对其进行格式化。

这是我尝试在 SMTP 采样器的“消息”文本框中使用 link 格式的原始 Gmail 文本示例:

Visit my account @dummyaccount<https://l.instagram.com/?u=https%3A%2F%2Ftaplink.> for more info.

希望在电子邮件中看到以下内容: 访问我的帐户@dummyaccount - @dummyaccount 是一个超级帐户link

实际: 访问我的帐户@dummyaccounthttps://l.instagram.com/?u=https%3A%2F%2Ftaplink.了解更多信息。

任何建议将不胜感激。

我认为您不能通过这种方式自定义 SMTP 采样器消息。您需要在电子邮件应用程序中撰写邮件,将其保存到 .eml file and send this .eml or if you want to build the message content dynamically you can use JSR223 Sampler and Groovy language 以发送您的邮件。

示例代码:

Properties props = new Properties();
props.put("mail.smtp.host", "your-smtp-server-here");
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");

def session = javax.mail.Session.getInstance(props, new CredentialsAuthentication() as javax.mail.Authenticator)
def msg = new javax.mail.internet.MimeMessage(session)

def from = new javax.mail.internet.InternetAddress("your-email-address-here", "your first and last name");
msg.setFrom(from);

def toAddress = new javax.mail.internet.InternetAddress("your-recipient-here ");

msg.setRecipient(javax.mail.Message.RecipientType.TO, toAddress);

msg.setSubject("Test");
msg.setContent("<html>\n" +
        "<body>\n" +
        "\n" +
        "<a href=\"http://link-to-your-instagram-profile\">\n" +
        "Link to my Instagram</a>\n" +
        "\n" +
        "</body>\n" +
        "</html>", "text/html")
javax.mail.Transport.send(msg);


class CredentialsAuthentication extends javax.mail.Authenticator {

    @Override
    protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
        return new javax.mail.PasswordAuthentication("your-username@most-probably-with-email.com", "your-password-here")
    }
}