cancel
Showing results for 
Search instead for 
Did you mean: 

sending email with attachment

albert
Champ in-the-making
Champ in-the-making
Hi,

I have been reading and looking for code to send email with attachment(s). I can only find that it is not possible with Alfresco JavaScript (thread http://forums.alfresco.com/viewtopic.php?t=5252&highlight=mail+attachment)

I suppose the bean class org.alfresco.repo.action.executer.MailActionExecuter should be extended to make this possible.
It uses org.springframework.mail.javamail.JavaMailSenderImpl which can send email with attachments.

How can I order the extended version of MailActionExecuter to send email with attachment?  What command should I put into the process definition?

Being an Alfresco newbie, I hope I express myself clear. Thanks in advance for your reaction.

Albert
1 REPLY 1

albert
Champ in-the-making
Champ in-the-making
To reply on my own thread…

As I understand, you can write your own action classes, which will be callable from AlfrescoJavaScript - if you set the appropriate spring configuration files correctly. (http://wiki.alfresco.com/wiki/JavaScript_API#Actions_API)

What I did (just to test this):

I rewrote bean class MailActionExecuter by adding a dummy variable foo + a getter and settermethod.
I compiled this as a jar file, which I added to directory /alfresco/WEB-INF/lib/
I rewrote following the lines of '\alfresco\WEB-INF\classes\alfresco\action-services-context.xml':

    <bean id="mail" class="myown.action.executer.MailAttachmentActionExecuter" parent="action-executer"> <!– class has been "org.alfresco.repo.action.executer.MailActionExecuter"–>
        <property name="mailService">
            <ref bean="mailService"></ref>
        </property>
        <property name="templateService">
            <ref bean="templateService"></ref>
        </property>
        <property name="personService">
            <ref bean="personService"></ref>
        </property>
        <property name="authenticationService">
            <ref bean="authenticationService"></ref>
        </property>
        <property name="nodeService">
            <ref bean="nodeService"></ref>
        </property>
        <property name="authorityService">
            <ref bean="authorityService"></ref>
        </property>
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"></ref>
        </property>
        <property name="headerEncoding">
            <value>${mail.header}</value>
        </property>
        <property name="fromAddress">
            <value>${mail.from.default}</value>
        </property>
    </bean>

I changed a line in an action file:

   <start-state name="start">
        <task name="ovs:startaanvraag" swimlane="initiator"></task>
      <transition name="" to="ControleerAanvraag"></transition>
      <event type="node-leave">
             <action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
            <script>      
                 var wf_Document = bpm_package.children[0];   
                 
                 var strEmail="";
                 var Straat="";
                 <!– Ontvangst bevestiging sturen naar de aanvrager –>
            if (wf_Document.properties["omgevingsvergunning:aanvragertype"]=="Particulier"){
               strEmail=wf_Document.properties["omgevingsvergunning:emailadres"];
               Straat=wf_Document.properties["omgevingsvergunning:adres"];               
            }else{
               strEmail=wf_Document.properties["omgevingsvergunning:bd_emailadres"];
               Straat=wf_Document.properties["omgevingsvergunning:bd_adres"];   
            }              
            var mail = actions.create("mail");         
            mail.parameters.to = strEmail;   
            mail.parameters.subject = Straat + " (1) Ontvangst omgevingsvergunning aanvraag nr "+wf_Document.properties["omgevingsvergunning:aanvraag_dossiernummer"];
            mail.parameters.from = "noreply@briksendam.nl";
            mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/OmgevingsvergunningETemplates/OntvangstBevestiging.ftl");
            mail.parameters.text = "Uw aanvraag voor een omgevingsvergunning is ontvangen en zal zo spoedig mogelijk intern worden doorgezonden ter verdere behandeling."; 
            mail.execute(wf_Document);                    
            mail.parameters.to= "overzicht@briksendam.nl";

            mail.parameters.foo = "this is what I have added…";   

            mail.execute(wf_Document);               
            <!–
            wf_Document.addAspect("omgevingsvergunning:eindOordeel", null);
            var userInfo = ovs_coordinator1.properties["cm:firstName"]+ " " + ovs_coordinator1.properties["cm:lastName"] + " (" + ovs_coordinator1.properties["cm:userName"] + ")";
            wf_Document.properties["omgevingsvergunning:coordinator"] = userInfo;          
            wf_Document.save();      
             –>
            </script>
         </action>
      </event>     
   </start-state>      

This does not work actually. Tomcat log file gives
14:55:00,500 ERROR [action.executer.MailActionExecuter] Failed to send email to T.Abarki@briksendam.nl
java.lang.NoClassDefFoundError: org/alfresco/service/cmr/repository/TemplateNode
   at com.atosorigin.repo.action.executer.MailAttachmentActionExecuter.createEmailTemplateModel(MailAttachmentActionExecuter.java:332)
   at com.atosorigin.repo.action.executer.MailAttachmentActionExecuter.access$4(MailAttachmentActionExecuter.java:326)
   at com.atosorigin.repo.action.executer.MailAttachmentActionExecuter$1.prepare(MailAttachmentActionExecuter.java:278)
   at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:347)
   at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:339)
   at com.atosorigin.repo.action.executer.MailAttachmentActionExecuter.executeImpl(MailAttachmentActionExecuter.java:312)
   … lots of code

Maybe I just did something wrong with Tomcat. I just want to know: am I right about AlfrescoJavaScript? Can you write your own Action classes and call them with AlfrescoJavaScript, or is it more to be done? Is it something I don't understand, or is it something that is not possible yet?

Greetings, Albert