Sending mails
[]
Target groups
- Administrator (Web)
- Developer (Java)
Context
The OnlineChannel can be configured to use the mailing capabilities of the censhare server. This is needed if activation mails should be send on new customer registrations.
To enable sending mails from OC
- the censhare server must be configured to allow the OnlineChannel to invoke server-commands.
- the OnlineChannel must be configured to provide and map the user-accounts available to the accounts registered on the server.
The Online Portal bundle contains mail templates for account messages (activation, forgot password, ...). These templates can be individualized. Mails can be send as html, text or both.
Prerequisites
- Administrator rights
- censhare-Client (java)
- censhare-AdminClient (java)
Configure censhare server
Use 'censhare Admin-Client' (java) and ensure the 'Configuration/Services/Online-Channel Command Service' is active.
Configure satellite configuration
Open the Command Service Configuration and edit or ensure the mail configuration:
<command name="oc.send-mail" timeout="60">
<users defaultuser="system">
<user name="system"></user>
</users>
</command>
Send custom mail from custom java component
In case a custom mail implementation must be done, this code snippet may be of value
ServiceKey serviceKey = new ServiceKey(CommandService.class.getName());
CommandService commandService = (CommandService) getContext().getSite().getOsgiBridge().getService(serviceKey);
try {
Command command = commandService.createCommand("oc.send-mail");
try {
AXml mergeXml = AXml.createElement("data");
mergeXml.put("mails@account-name", accountName.get()); // name of mail account configuration as configured in admin client
AXml mailXml = mergeXml.create("mails.mail");
mailXml.put("content@mimetype", "text/plain; charset=utf-8");
mailXml.setAttr("subject", "My mail for foo");
mailXml.put("recipient@address", "jane.doe@example.com");
mailXml.put("content", "This is our message to you.");
command.mergeSlot("", mergeXml);
command.execute();
}
finally {
if(command.getStatus().equals(STATUS.ERROR))
resultCode.set(ResultCodes.ERROR_UNSPECIFIED);
else
resultCode.set(ResultCodes.SUCCESS);
command.release();
}
}
finally {
getContext().getSite().getOsgiBridge().ungetService(serviceKey);
}