Custom email action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2013 08:42 AM
I have to make a custom email action in more menu in document library section. I succeeded in showing the action in drop down menu by following the blog
http://ecmstuff.blogspot.in/2012/04/adding-document-library-actions-in.html
but when click on it, the form is not showing the labels in it.
How can i get the form with the labels (To, subject and body).
Thanks
Nancy
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2013 07:52 AM
I have added all the files according to the post which you mention above but still i am not able to send the document as an attachment in mail.
As in Martin Bergljung blog class sendAsEmailActionExecuter do i have to write the below part also in the code?
// Get document filename Serializable filename = m_nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_NAME); if (filename == null) { throw new AlfrescoRuntimeException("Document filename is null"); } String documentName = (String) filename; try { // Create mail session Properties props = new Properties(); props.put("mail.smtp.host", "XXXXXX"); // localhost will not work Session session = Session.getDefaultInstance(props, null); session.setDebug(false); // Define message Message message = new MimeMessage(session); String fromAddress = "alfresco@mycompany.com"; message.setFrom(new InternetAddress(fromAddress)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); // Create the message part with body text BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(body); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); // Create the Attachment part // Get the document content bytes byte[] documentData = alfrescoRepoHelper.getDocumentContentBytes(actionedUponNodeRef, documentName); if (documentData == null) { throw new AlfrescoRuntimeException("Document content is null"); } // Attach document messageBodyPart = new MimeBodyPart(); messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource( documentData, new MimetypesFileTypeMap().getContentType(documentName)))); messageBodyPart.setFileName(documentName); multipart.addBodyPart(messageBodyPart); // Put parts in message message.setContent(multipart); // Send the message Transport.send(message);
if yes, i have added the code but not able to send the mail
and also have to add the file named SendDocInEmailWebscript ?
As you said try sending test mail using java script console, i tried and i am able to send the test mail.
But how to send the document?
Nancy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2013 08:45 AM
Yes you have to add the full code for the class sendAsEmailActionExecuter, and to adapt it to your needs and configuration : change
props.put("mail.smtp.host", "smtp.mycompany.com");
and
String fromAddress = "alfresco@mycompany.com";
No you don't have to add SendDocInEmailWebscript, but you need to add the class AlfrescoRepoHelper in order to be able to get the file linked to a noderef. The source file is located in _alfresco\source\java\com\mycompany\cms\util\.
If it's not working, can you post your log file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2013 12:02 PM
I have already added the file alftrescoRepoHelper but still not able to email.
My log files are clean there is no error in it.
MY LOG FILE IS BELOW:
15:18:13,521 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'sysAdmin' subsystem, ID: [sysAdmin, default]15:18:13,552 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'sysAdmin' subsystem, ID: [sysAdmin, default] complete15:18:23,162 INFO [org.springframework.extensions.webscripts.TemplateProcessorRegistry] Registered template processor Repository Template Processor for extension ftl15:18:23,162 INFO [org.springframework.extensions.webscripts.ScriptProcessorRegistry] Registered script processor Repository Script Processor for extension js15:18:26,594 INFO [org.alfresco.repo.domain.schema.SchemaBootstrap] Connecting to database: jdbc:mysql:///alfresco, UserName=alfresco@localhost, MySQL-AB JDBC Driver15:18:26,594 INFO [org.alfresco.repo.domain.schema.SchemaBootstrap] Schema managed by database dialect org.hibernate.dialect.MySQLInnoDBDialect.15:18:28,122 INFO [org.alfresco.repo.domain.schema.SchemaBootstrap] No changes were made to the schema.15:18:29,230 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'Search' subsystem, ID: [Search, managed, lucene]15:18:29,480 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'Search' subsystem, ID: [Search, managed, lucene] complete15:18:30,400 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'thirdparty' subsystem, ID: [thirdparty, default]15:18:32,756 WARN [org.alfresco.util.OpenOfficeConnectionTester] An initial OpenOffice connection could not be established.15:18:32,756 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'OOoDirect' subsystem, ID: [OOoDirect, default] complete15:18:33,255 WARN [org.alfresco.repo.admin.ConfigurationChecker] The Alfresco 'dir.root' property is set to a relative path './alf_data'. 'dir.root' should be overridden to point to a specific folder.15:18:33,255 INFO [org.alfresco.repo.admin.ConfigurationChecker] The Alfresco root data directory ('dir.root') is: .\alf_data15:18:33,442 INFO [org.alfresco.repo.admin.patch.PatchExecuter] Checking for patches to apply …15:18:33,832 INFO [org.alfresco.repo.admin.patch.PatchExecuter] No patches were required.15:18:33,848 INFO [org.alfresco.repo.module.ModuleServiceImpl] Found 1 module(s).15:18:33,863 INFO [org.alfresco.repo.module.ModuleServiceImpl] Starting module 'alfresco-mm-repo' version 0.1.5.9.15:18:33,863 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'fileServers' subsystem, ID: [fileServers, default]15:18:34,316 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'Authentication' subsystem, ID: [Authentication, managed, alfrescoNtlm1]15:18:34,409 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'Authentication' subsystem, ID: [Authentication, managed, alfrescoNtlm1] complete15:18:34,550 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'fileServers' subsystem, ID: [fileServers, default] complete15:18:34,550 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'imap' subsystem, ID: [imap, default]15:18:34,987 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'imap' subsystem, ID: [imap, default] complete15:18:34,987 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'email' subsystem, ID: [email, outbound]15:18:35,018 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'email' subsystem, ID: [email, outbound] complete15:18:35,018 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'email' subsystem, ID: [email, inbound]15:18:35,080 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'email' subsystem, ID: [email, inbound] complete15:18:35,080 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'googledocs' subsystem, ID: [googledocs, default]15:18:35,127 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'googledocs' subsystem, ID: [googledocs, default] complete15:18:35,127 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'Subscriptions' subsystem, ID: [Subscriptions, default]15:18:35,127 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'Subscriptions' subsystem, ID: [Subscriptions, default] complete15:18:35,127 INFO [org.alfresco.repo.usage.UserUsageTrackingComponent] Disabled - clear non-missing user usages …15:18:35,143 INFO [org.alfresco.repo.usage.UserUsageTrackingComponent] Found 1 users to clear15:18:35,626 INFO [org.alfresco.repo.usage.UserUsageTrackingComponent] … cleared non-missing usages for 1 users15:18:35,626 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'Synchronization' subsystem, ID: [Synchronization, default]15:18:35,704 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'Synchronization' subsystem, ID: [Synchronization, default] complete15:18:35,798 INFO [org.alfresco.service.descriptor.DescriptorService] Alfresco JVM - v1.7.0-b147; maximum heap size 989.875MB15:18:35,798 INFO [org.alfresco.service.descriptor.DescriptorService] Alfresco started (Community). Current version: 4.2.0 (@build-number@) schema 6,020. Originally installed version: 4.2.0 (@build-number@) schema 6,020.15:18:35,798 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'ActivitiesFeed' subsystem, ID: [ActivitiesFeed, default]15:18:35,860 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'ActivitiesFeed' subsystem, ID: [ActivitiesFeed, default] complete15:18:35,860 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Starting 'Replication' subsystem, ID: [Replication, default]15:18:35,860 INFO [org.alfresco.repo.management.subsystems.ChildApplicationContextFactory] Startup of 'Replication' subsystem, ID: [Replication, default] complete15:18:36,141 DEBUG [org.alfresco.repo.action.executer.MailActionExecuter] {template_model={repeatIntervalMins=1440, feedItemsCount=1, feedItemsMax=100, activities=[{id=7, siteNetwork=demo, feedUserId=nancy, postUserId=nancy, postDate=Tue Sep 10 13:04:09 IST 2013, activitySummary={lastName=aggarwal, title=nancy aggarwal (nancy), memberLastName=aggarwal, role=SiteCollaborator, firstName=nancy, memberUserName=nancy, memberFirstName=nancy}, activityType=org.alfresco.site.user-joined, activitySummaryFormat=json}], productName=Share, siteTitles={demo=demo}, personProps={cm:lastName=aggarwal, sys:node-uuid=1aa6f015-48dd-47eb-b844-601b53ec5782, cm:firstName=nancy, cm:name=1aa6f015-48dd-47eb-b844-601b53ec5782, sys:locale=en_US, cm:owner=nancy, sys:store-protocol=workspace, cm:userName=nancy, cm:homeFolderProvider=userHomesHomeFolderProvider, sys:node-dbid=857, cm:sizeQuota=-1, cm:sizeCurrent=null, cm:email=XXXXXX, cm:homeFolder=workspace://SpacesStore/, sys:store-identifier=SpacesStore}}, template=workspace://SpacesStore/, to=xxxxxx, subject=Alfresco Share: Recent Activities}15:18:40,899 INFO [org.springframework.extensions.webscripts.DeclarativeRegistry] Registered 470 Web Scripts (+0 failed), 749 URLs15:18:40,899 INFO [org.springframework.extensions.webscripts.DeclarativeRegistry] Registered 2 Package Description Documents (+0 failed) 15:18:40,899 INFO [org.springframework.extensions.webscripts.DeclarativeRegistry] Registered 1 Schema Description Documents (+0 failed) 15:18:40,899 INFO [org.springframework.extensions.webscripts.AbstractRuntimeContainer] Initialised Repository Web Script Container (in 4342.737ms)15:18:40,930 INFO [org.springframework.extensions.webscripts.TemplateProcessorRegistry] Registered template processor freemarker for extension ftl15:18:40,930 INFO [org.springframework.extensions.webscripts.ScriptProcessorRegistry] Registered script processor javascript for extension js
What to do now?
Nancy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2013 01:12 PM
to help you I created an eclipse project in which you will find only the needed files to get it work : <a href="https://dl.dropboxusercontent.com/u/52624874/ecy-sample-repo.zip">ecy-sample-repo.zip</a>.
Only the 2 java files listed above are needed, and the context file to declare them + the share-config-custom.xml file.
The build.xml file is a little bit modified to allow the copy of the share-config-custom.xml file at the right place.
You just have to launch ant task hotcopy-tomcat-zip to get all elements deployed, and it should run.
Becareful : perhaps is there still the file /tomcat/shared/classes/alfresco/extension/sendasemail-action-context.xml present on your alfresco instance ! This file was useful to get the custom form working, but is no more needed.
You will have to delete it because another context file named services-context.xml gets necessary bean declaration.
let's know if this is working now.
Good luck !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2013 07:35 AM
I have added the above files as you said but still no progress.
I think the problem is my form is not getting mapped with action executer. As in my log file also there is no error regarding action.
I have attached the output what is coming when i click on ok to send the mail below.
Nancy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2013 10:13 AM
some checking you can do :
does your config in share-config-custom.xml match the parameters waited by the SendAsEmailActionExecuter class ?
in share-config-custom.xml, fields are to, subject and body_text
<config evaluator="string-compare" condition="send-as-email"> <forms> <form> <field-visibility> <show id="to" /> <show id="subject" /> <show id="body_text" /> </field-visibility> <appearance> <field id="to" label-id="send-as-email.field.to"/> <field id="subject" label-id="send-as-email.field.subject"/> <field id="body_text" label-id="send-as-email.field.text"/> <control template="/org/alfresco/components/form/controls/textarea.ftl" /> </appearance> </form> </forms> </config>
in the SendAsEmailActionExecuter class, parameters are to, subject and body_text
public class SendAsEmailActionExecuter extends ActionExecuterAbstractBase { private static Log logger = LogFactory.getLog(SendAsEmailActionExecuter.class); // Form parameters public static final String PARAM_EMAIL_TO_NAME = "to"; public static final String PARAM_EMAIL_SUBJECT_NAME = "subject"; public static final String PARAM_EMAIL_BODY_NAME = "body_text";
<br>
Did you replace following lines in the SendAsEmailActionExecuter class with yours ?
line 81 -
props.put("mail.smtp.host", "alfea-port-1103");
and line 87 - String fromAddress = "alfresco@alfea-port-1103.com";
To know what's happening whith your code, in the class you can add logger messages this way :
logger.debug("my message");
To see your messages in the log, you need to add following to the [ALFRESCO]\tomcat\shared\classes\alfresco\extension\log4j-dev.properties file :
log4j.logger.com.mycompany.cms.action.SendAsEmailActionExecuter=debug
This will help you to understand what's not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2013 12:57 AM
I have done the checking that you said but still no success.
If I put the below code in share-config-custom.xml then my form doesn't appear and if i place my code in share-form-config.xml them i am able to see the form.
<config evaluator="string-compare" condition="send-as-email"> <forms> <form> <field-visibility> <show id="to" /> <show id="subject" /> <show id="body_text" /> </field-visibility> <appearance> <field id="to" label-id="send-as-email.field.to"/> <field id="subject" label-id="send-as-email.field.subject"/> <field id="body_text" label-id="send-as-email.field.text"/> <control template="/org/alfresco/components/form/controls/textarea.ftl" /> </appearance> </form> </forms> </config>
and if i write body_text then text field doesn't appear, if i write text then it appears.
I have already replaces the below lines with mine
props.put("mail.smtp.host", "smtp.mycompany.com");String fromAddress = "alfresco@org.com";
I also added the line
logger.debug("my message");
and in log4j.properties file the below line
log4j.logger.com.mycompany.cms.action.SendAsEmailActionExecuter=debug
but these messages doesn't show up in the log files.
I am not able to understand what is not working.
Nancy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2013 03:36 AM
you probably installed an extension on your system, through an AMP, with which a share-config-custom.xml file is deployed in [ALFRESCO]\tomcat\webapps\share\WEB-INF\classes\alfresco\web-extension. Can you check this ?
If it is, this share-config-custom.xml is used rather than the one in [ALFRESCO]\tomcat\shared\classes\alfresco\web-extension. You will have to merge those 2 files to get only one.
It could also be an extension via a JAR file, in which is present a share-config-custom file. The same apply : you will have to merge the 2 files and to keep only one.
Another thing : check that you don't have another xxx-context.xml file defining a bean with id "send-as-email". I think you probably have 2 different files defining this bean, and the wrong is used. If so, remove the unneeded one.
Last thing : if you changed the package of the SendAsEmailActionExecuter class, you will have to change the same way the line in your log4j.properties file, to get logs from your class.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2013 06:56 AM
I have only one file in [alfresco]\tomcat\shared\classes\alfresco\web-extention.
I don't have web-extention directory in [alfresco]\tomcat\webapps\share\web-inf\classes\alfresco\web-extention.
Secondly: I have checked for the xxx-context.xml file defining a bean with name "send-as-email" and i have only i context.xml with this bean.
lastly: I have written the same package in which my file is placed and still i am not getting any logs regarding the action.
one more thing: In your previous popst you asked me to add file sendasemail-action-context.xml in extention directory and you also asked to add following code in services-context.xml… so i have to add both the files or just only the last one?
<bean id="send-as-email" class="com.mycompany.cms.action.SendAsEmailActionExecuter" parent="action-executer"> <property name="alfrescoRepoHelper"> <ref bean="alfrescoRepoHelper"/> </property> <property name="nodeService"> <ref bean="NodeService"/> </property> </bean>
Do i have to write javascript and webscript also because in the blog he said for rest of teh implementation part download source code.
Nancy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2013 10:42 AM
Sorry if I was not clear in my previous explanations, and thanks for the checks you made.
First you're right regarding the logs that do not appear. I made a mistake in the name of the file, which cannot be used as a log4j properties file. The name should be xxx-log4j.properties for it to work, so please change the name from log4j-dev.properties to dev-log4j.properties. You should see your messages this way.
Second you should get only one file to declare the bean send-as-email. The only file you should get is services-context.xml, you can delete the first file I told you about in the first posts named sendasemail-action-context.xml.
Finally you should be able to test the java action class, with following script in the javascript console :
// you can use whatever document node you want, nothing is done with that document !var document = utils.getNodeFromString("workspace://SpacesStore/1560d1bb-80fa-43f6-87bf-6937b085407e");var mail = actions.create("send-as-email");mail.parameters.to = "recipient@email.address";mail.parameters.subject = "Sending mail test";mail.parameters.from = "sender@email.address";mail.parameters.body_text = "email content";mail.parameters.node = document;mail.execute(document);
This should send you an email with your document attached.
Does it work ?