-1

I am using alfresco community edition-5.1.x,I have configured email notification with attachment is not working,

var mail = actions.create('mail');
mail.parameters.to='${bmp_traineremail}';
mail.parameters.cc='';
mail.parameters.from='xxx@gmail.com';
mail.parameters.node=bpm_package.children[0];
mail.parameters.subject='Congrats ${bmp_trainername}';
mail.parameters.text='Hello ${trainerempanelment_trainername},\n\
mail.execute(bpm_package);

Please help me out.

Paul
  • 141
  • 1
  • 11
  • Is it normal that mail.parameters.text doesnt have a final quote ? => 'Hello ${trainerempanelment_trainername},\n\ – Akah Aug 09 '16 at 06:38
  • yes,this is final quote, my problem is not attaching attachments – Paul Aug 09 '16 at 08:40

1 Answers1

1

Alfresco doesnt support mail attachments out of the box.

You might want to edit the MailActionExecuter class and add a parameter for attachments, then add these as a mimemultipart message. like so:

 public static final String PARAM_ATTACHMENTS = "attachments";

 public void prepare(MimeMessage mimeMessage) throws MessagingException{
 ...
            MimeMultipart content = new MimeMultipart("mixed");  
            MimeBodyPart textPart = new MimeBodyPart();
            if (isHTML){
                textPart.setContent(text, "text/html; charset=utf-8");
            } else {
                textPart.setText(text);
            }
            content.addBodyPart(textPart);
            List<NodeRef> attachments = (List<NodeRef>) ruleAction.getParameterValue(PARAM_ATTACHMENTS);
            if (attachments != null){
                for (final NodeRef attachnode : attachments){
                    MimeBodyPart attachment = new MimeBodyPart();  
                    final String filename = nodeService.getProperty(attachnode, ContentModel.PROP_NAME).toString();
                    attachment.setFileName(filename);
                    attachment.setDataHandler(new DataHandler(new DataSource() {  
                        public InputStream getInputStream() throws IOException {  
                            return serviceRegistry.getContentService().getReader(attachnode, ContentModel.PROP_CONTENT).getContentInputStream();  
                        }  
                        public OutputStream getOutputStream() throws IOException {
                            throw new IOException("Read-only data");  
                        }  
                        public String getContentType() {  
                            return serviceRegistry.getContentService().getReader(attachnode, ContentModel.PROP_CONTENT).getMimetype();  
                        }  
                        public String getName() {  
                            return filename;
                        }  
                    }));  
                    content.addBodyPart(attachment);  
                }
            }
            mimeMessage.setContent(content);

You can use the mailAction like this:

        ActionService actionService = serviceRegistry.getActionService();
        Action mailAction = actionService.createAction(MailActionExecuter.NAME);
        mailAction.setParameterValue(MailActionExecuter.PARAM_TO , "me@gmail.com" );
        List<NodeRef> attachements = new ArrayList<>();
        //TODOD add noderefs to attachements list... 
        mailAction.setParameterValue(MailActionExecuter.PARAM_ATTACHMENTS, attachements );
        actionService.executeAction(mailAction, null);
Stefan De Laet
  • 1,409
  • 11
  • 20