This content has been marked as final.
Show 3 replies
-
1. Re: Programmatic mail-session configuration
ctomc Oct 22, 2012 4:25 PM (in response to alexkashrus)Hi,
you are close first you added session, now you also need to add server.
public static void createMailSession(ModelControllerClient client, String sessionJndi) throws IOException { ModelNode requestSession = new ModelNode(); requestSession.get(ClientConstants.OP).set(ClientConstants.ADD); requestSession.get(ClientConstants.OP_ADDR).add("subsystem","mail"); requestSession.get(ClientConstants.OP_ADDR).add("mail-session",sessionJndi); requestSession.get("jndi-name").set(sessionJndi); ModelNode requestServer = new ModelNode(); requestServer.get(ClientConstants.OP).set(ClientConstants.ADD); requestServer.get(ClientConstants.OP_ADDR).add("subsystem","mail"); requestServer.get(ClientConstants.OP_ADDR).add("mail-session",sessionJndi); requestServer.get(ClientConstants.OP_ADDR).add("mail-server","smtp"); requestServer.get("outbound-socket-binding-ref").set("mail-smtp"); requestServer.get("username").set("some-user-name"); requestServer.get("password").set("password"); ModelNode result = client.execute(new OperationBuilder(requestSession).build()); ModelNode result2 = client.execute(new OperationBuilder(requestServer).build()); ... String outcome = result.get(ClientConstants.OUTCOME).asString(); String description = ""; if (outcome.equalsIgnoreCase("failed")) { description += " ,Reason: " + result.get(ClientConstants.FAILURE_DESCRIPTION).asString(); } System.out.println("Adding MailSession: " + sessionJndi + " Result: " + outcome + description); }
hope this helps,
tomaz
-
2. Re: Programmatic mail-session configuration
alexkashrus Oct 22, 2012 5:00 PM (in response to ctomc)This doesn't seem to be working it still creates an empty "mail-session"
-
3. Re: Programmatic mail-session configuration
alexkashrus Oct 22, 2012 7:19 PM (in response to ctomc)1 of 1 people found this helpfulrequestServer.get(ClientConstants.OP_ADDR).add("mail-server","smtp");
must be
requestServer.get(ClientConstants.OP_ADDR).add("server","smtp");
then it works