cancel
Showing results for 
Search instead for 
Did you mean: 

How to send mail with attachment in Alfresco?

fredayin
Champ in-the-making
Champ in-the-making
I've heard Alfresco 2.9 can support send mail with attachments.  But how to do it?

Thanks!
4 REPLIES 4

fbehfar
Champ on-the-rise
Champ on-the-rise
Hi,
If I got you right, you want to send and email when a user upload a content, if so,
you can do it with the help of the rules,

in rule defintion:
set the sondition to "All items", (or any other condition)
set the action to "Send an email to specified users",

hope it helps,
FSB

tommorris
Champ in-the-making
Champ in-the-making
Are you mainly interested in how to attach a file to an email, or how to send an email anyway?
Is sending a plain email with a URL to the file in the repository an option for you?

A space-rule could execute a javascript action that sends an email pointing to the document. The javascript would probably look something like:

var mail = actions.create('mail');
mail.parameters.to = 'a@b.com'; // or maybe person.properties["cm:email"];
mail.parameters.from = 'alfresco@system.com';
mail.parameters.subject = 'Please Review this Document';
mail.parameters.text = 'Blah blah blah\n\n';
mail.parameters.text += 'Doc: http://www.srv.com/alfresco/d/a/workspace/SpacesStore/a9...fd/doc.pdf';
mail.execute(document);

krishherein
Champ in-the-making
Champ in-the-making
I want to know what is 'document' in  last line,
mail.execute(document);

I tried it but i am not able to run it successfully, i need to define 'documnet'.

calle
Champ in-the-making
Champ in-the-making
The MailActionExecuter does not support attachments, though it is easy to rewrite it to handle attachments.

Basically, this is how you extend it:

for (final NodeRef attachmentNodeRef : attachments) {
                  
                  final MimeBodyPart attachment = new MimeBodyPart();
                  attachment.setDataHandler(new DataHandler(new DataSource() {
   
                     public InputStream getInputStream() throws IOException {
                        ContentReader reader = contentService.getReader(attachmentNodeRef, ContentModel.PROP_CONTENT);
                        return reader.getContentInputStream();
                     }
   
                     public OutputStream getOutputStream() throws IOException {
                        throw new IOException("Read-only data");
                     }
   
                     public String getContentType() {
                        return contentService.getReader(attachmentNodeRef, ContentModel.PROP_CONTENT).getMimetype();
                     }
   
                     public String getName() {
                        return nodeService.getProperty(attachmentNodeRef, ContentModel.PROP_NAME).toString();
                     }
                     
                     
                  }));
                  
                  attachment.setFileName(nodeService.getProperty(attachmentNodeRef, ContentModel.PROP_NAME).toString());
                  
                  content.addBodyPart(attachment);
                  
                  
               }

This assumes that you somehow has passed the nodes representing the attachments to the action, for example as a parameter.

//Carl