Hello, this is my alfresco-global.properties emails configurations.
...
...
### Email settings ###
mail.encoding=UTF-8
mail.host=smtp.uci.cu
mail.protocol=smtp
mail.port=587
mail.username=liomar@xxxx.cu
mail.password=****************
mail.from.default=liomar@xxxx.cu
mail.smtp.auth=true
mail.smtp.starttls.enable=true
...
...
It's working.
But I have a question: How can I use the same "mail.from.default" previously configured in alfresco-global.properties in the method sendMail created in JS.
function sendMail(email, subject, message, node) {
var mail = actions.create('mail');
mail.parameters.to = email;
mail.parameters.subject = subject;
mail.parameters.text = message;
mail.parameters.from = 'liomar@xxxx.cu';
// It is necessary to pass the created node
mail.execute(node);
}
This method is working too, but I want to reuse the same parameter 'mail.from.default' previously configured without rewriting literally 'liomar@xxxx.cu';
Solved! Go to Solution.
Thanks Angel, I found the solution using your code with the next changes:
Creation of a file custom-global-properties-context.xml in \tomcat\webapps\alfresco\WEB-INF\classes\alfresco that contains
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="globalPropertiesBean" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:alfresco-global.properties</value>
</list>
</property>
</bean>
</beans>
Creation of a file cgp.js in tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension\scripts that contain
var ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var ctxt_properties = ctxt.getBean('global-properties', java.util.Properties);
var ctxt_properties_mail_from_default = ctxt_properties["mail.from.default"];
That is all, you must use that in webscript service, but if you want use in JavaScript console, is important to write the next importation
<import resource="classpath:alfresco/extension/scripts/cgp.js">
It's not available in the JavaScript API, but you can recover the value with following code:
var ctxt =
Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext(); var properties =
ctxt.getBean('global-properties', java.util.Properties); logger.log(properties["mail.from.default"]);
Greatings angelborroy, this is the answer of JavaScript console:
Failed to execute script 'Javascript Console Script': Invalid bean definition with name 'global-properties' defined in class path resource [alfresco/core-services-context.xml]: Can only specify arguments for the getBean method when referring to a prototype bean definition
What I see, I haven't definition of core-services-context.xml in my system files of alfresco 5.2.
I'm looking in this repository https://github.com/surevine/alfresco-repository-client-customisations/blob/master/config/alfresco/co..., the way to get a solution to my problem, this is giving me many issues 'cause I didn't use LUCENE, im using SOLR4. Maybe if i could find the way to only get the bean around global-properties...
Thanks Angel, I found the solution using your code with the next changes:
Creation of a file custom-global-properties-context.xml in \tomcat\webapps\alfresco\WEB-INF\classes\alfresco that contains
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="globalPropertiesBean" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:alfresco-global.properties</value>
</list>
</property>
</bean>
</beans>
Creation of a file cgp.js in tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension\scripts that contain
var ctxt = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
var ctxt_properties = ctxt.getBean('global-properties', java.util.Properties);
var ctxt_properties_mail_from_default = ctxt_properties["mail.from.default"];
That is all, you must use that in webscript service, but if you want use in JavaScript console, is important to write the next importation
<import resource="classpath:alfresco/extension/scripts/cgp.js">
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.