02-20-2024 03:35 PM
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';
02-27-2024 01:19 PM
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">
02-21-2024 02:16 AM
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"]);
02-21-2024 11:29 AM
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...
02-27-2024 01:19 PM
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">
Explore our Alfresco products with the links below. Use labels to filter content by product module.