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);