我已经在下面编写了Java代码段(java简单邮件4.4.5):
private String setSOCKS5ProxyAuthentication(String subaccount, String locationId) {
final String encodedSubaccount = new String(Base64.encodeBase64(subaccount.getBytes()));
final String encodedLocationId = new String(Base64.encodeBase64(locationId.getBytes()));
String submitter = "1." + encodedSubaccount + "." + encodedLocationId;
Authenticator.setDefault(new Authenticator() {
@Override
protected java.net.PasswordAuthentication getPasswordAuthentication() {
return new java.net.PasswordAuthentication("1." + encodedSubaccount + "." + encodedLocationId,
new char[] {});
}
});
return submitter;
}
public void sendEmail(字符串从,字符串到,字符串subjectText,字符串mailText)抛出IOException,MessagingException {
String submitter = setSOCKS5ProxyAuthentication("accountname", "location");
Mailer mailer = new Mailer(
new ServerConfig("mailrouter", 9000, "", ""),
TransportStrategy.SMTP_PLAIN,
new ProxyConfig("localhost", 20004, submitter,"password")
);
mailer.sendMail(new EmailBuilder()
.from("mytest", "sender@gmail.com")
.to("test", "receiver@gmail.com")
.subject("This is the subject line")
.textHTML("<h1>This is the actual message</h1>")
.build());
}
这不起作用,因为它引发了异常“第三方错误”。 我的SOCKS代理是localhost:20004,用户名如上所述确定,但没有密码。我必须提供伪造的密码,否则API会引发异常。 没有身份验证,并且传输安全性为无。 邮件服务器host:port是mailrouter:9000
我在做什么错了?