Hi Michael
A look at my code reveals this is very complex, I cant tell cfmail
which lib to use (obviously) and in order to do so in my code its
tricky:
I have a method "getConnectionSettings" which is basically a wrapper
of javax.mail.Session.getInstance(prop) as you can see this is a
static function , so I need to find how to use a class loader in java
to get me the version I want.
Unless this version of createobject loads all dependencies of that lib
only (or with higher priority).
I will gave this a try:
<cfset sVars.cJar = expandPath("/../bin/emailfetcher/
emailfetcher.jar") />
<cfset sVars.jCU = createObject("java", "ConnectionUtils",
sVars.cJar) />
<cfset sVars.jS = createObject("java", "javax.mail.Session",
sVars.cJar) />
<cfset sVars.cs = sVars.jCU.getConnectionSettings(arguments.cProvider,
arguments.cPort, arguments.bSsl, arguments.bTls, arguments.cHostname,
arguments.cLogin, arguments.cPwd) />
<cfset sVars.oSession = sVars.jCU.getMailserverSession(sVars.cs,
arguments.nTimeout, true, sVars.jS) />
but unfortunatley it did not work :(
railo.runtime.java.JavaObject cannot be cast to javax.mail.Session
java code:
public ConnectionSettings getConnectionSettings(String protocol,
String port, boolean ssl, boolean tls, String hostname, String login,
String pwd){
return new ConnectionSettings(new Protocol(protocol, port, ssl,
tls), hostname, login, pwd);
}
public javax.mail.Session getMailserverSession(ConnectionSettings c,
int timeout) throws Exception {
return getMailserverSession(c, timeout, false);
}
public javax.mail.Session getMailserverSession(ConnectionSettings c,
int timeout, boolean testPortAndHost) throws Exception {
return getMailserverSession(c, timeout, false, null);
}
public javax.mail.Session getMailserverSession(ConnectionSettings c,
int timeout, boolean testPortAndHost, Object session) throws Exception
{
int port = Integer.parseInt(c.protocol.port);
if(testPortAndHost && !testPortConnection(c.hostname, port,
timeout))
throw new javax.mail.MessagingException("Could not open port");
java.util.Properties prop = new java.util.Properties();
String prot = c.protocol.protocol;
prop.put("mail." + prot + ".connectiontimeout", timeout);
prop.put("mail." + prot + ".timeout", timeout);
prop.put("mail." + prot + ".host", c.hostname);
prop.put("mail." + prot + ".port", port);
if(c.protocol.tls) {
prop.put("mail." + prot + ".starttls.enable", "true");
}
if(c.login.length() > 0) {
prop.put("mail." + prot + ".auth", "true");
prop.put("mail." + prot + ".user", c.login);
if(c.pwd.length() > 0)
prop.put("mail." + prot + ".password", c.pwd);
}
return session == null ? javax.mail.Session.getInstance(prop) :
((javax.mail.Session)session).getInstance(prop);
}
Regards
GX