我曾尝试使用SMTP Sampler发送电子邮件,但无法发送。出现以下错误并显示500个响应代码。
Response code: 500
Response message: Could not connect to SMTP host: smtp.gmail.com, port: 587
答案 0 :(得分:0)
首先使用telnet client或同等功能检查从计算机到587
主机的端口smtp.gmail.com
的连接,您应该看到类似以下内容的
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP g20sm1259543lfh.33 - gsmtp
如果您将无法看到以上输出-可能是操作系统或路由器firewall阻止了对Gmail SMTP端口的访问,因此您需要与网络管理员联系以获得访问权限
您的组织可能正在使用corporate proxy访问Internet。在这种情况下-您将无法使用SMTP Sampler,因为它不支持代理配置especially if the authentication is required。在这种情况下,您将需要切换到JSR223 Sampler并编写使用Groovy语言发送电子邮件的逻辑。
将以下代码放入“脚本”区域:
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("smtp.gmail.com", 587)
.withSMTPServerUsername("Your SMTP Username")
.withSMTPServerPassword("Your SMTP Password")
.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("SMTP FROM address (in the majority of cases the same as SMTP Username)")
.to("Recipient")
.withSubject("test script")
.withPlainText("test message")
.buildEmail()
mailer.sendMail(email)