是的,您可以使用SMTP Sampler来发送不带附件的电子邮件。以下是一个示例代码,演示如何使用SMTP Sampler发送邮件:
import javax.mail.Message
import javax.mail.Session
import javax.mail.Transport
import javax.mail.internet.InternetAddress
import javax.mail.internet.MimeMessage
String smtpHost = "your.smtp.host" // 设置SMTP服务器
int smtpPort = 25 // 设置SMTP端口号
String from = "sender@example.com" // 发件人邮箱地址
String to = "recipient@example.com" // 收件人邮箱地址
String subject = "Test Email" // 邮件主题
String body = "This is a test email." // 邮件正文
Properties properties = new Properties()
properties.put("mail.smtp.host", smtpHost)
properties.put("mail.smtp.port", String.valueOf(smtpPort))
Session session = Session.getDefaultInstance(properties)
MimeMessage message = new MimeMessage(session)
message.setFrom(new InternetAddress(from))
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to))
message.setSubject(subject)
message.setText(body)
Transport.send(message)
请注意,您需要在JMeter的lib文件夹中添加相应的Java Mail库文件,以便能够使用SMTP Sampler发送电子邮件。