我认为 sfussenegger 的想法是正确的。但是,不使用自定义身份验证器,通过 connect(..) 进行身份验证怎么样?只用 Gmail 测试过。但这似乎有效。
EDIT:我用 CF9 和 OBD 成功测试了这一点。不幸的是,我对 Railo 没有什么好感……真是太糟糕了。
EDIT:更新以添加缺少的“mail.smtp.auth”属性。现在它也应该可以与 Railo 一起正常工作。
//Java Version
int port = 587;
String host = "smtp.gmail.com";
String user = "[email protected] /cdn-cgi/l/email-protection";
String pwd = "email password";
try {
Properties props = new Properties();
// required for gmail
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
// or use getDefaultInstance instance if desired...
Session session = Session.getInstance(props, null);
Transport transport = session.getTransport("smtp");
transport.connect(host, port, user, pwd);
transport.close();
System.out.println("success");
}
catch(AuthenticationFailedException e) {
System.out.println("AuthenticationFailedException - for authentication failures");
e.printStackTrace();
}
catch(MessagingException e) {
System.out.println("for other failures");
e.printStackTrace();
}
<cfscript>
//CF Version
port = 587;
host = "smtp.gmail.com";
user = "[email protected] /cdn-cgi/l/email-protection";
pwd = "email password";
try {
props = createObject("java", "java.util.Properties").init();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
// or use getDefaultInstance instance if desired...
mailSession = createObject("java", "javax.mail.Session").getInstance(props, javacast("null", ""));
transport = mailSession.getTransport("smtp");
transport.connect(host, port, user, pwd);
transport.close();
WriteOutput("success");
}
//for authentication failures
catch(javax.mail.AuthenticationFailedException e) {
WriteOutput("Error: "& e.type &" ** "& e.message);
}
// for other failures
catch(javax.mail.MessagingException e) {
WriteOutput("Error: "& e.type &" ** "& e.message);
}
</cfscript>