cancel
Showing results for 
Search instead for 
Did you mean: 

Attach a document into an email

mvicidomini
Champ in-the-making
Champ in-the-making
Hello all,

i would like to attach a document when it is uploaded to alfresco. I know that there is the default notification from the workflow but for internal reason my customers ask me to attach the original document into an email. I have writen a small script but i don't manage to attach the document does somebody has a solution thanks a lot.

var mail = actions.create("mail");
var docName = document.properties["name"];
var siteShortName = document.siteShortName;
//var mySite = getSite(shortName);
var prop = document.properties["nodeRef"]
mail.parameters.to = "MY EMAIL";
mail.parameters.subject = "Ajout de document";
mail.parameters.from = "MY EMAIL";
mail.parameters.text = "Ajout du document " + docName + "Sur le site: "+siteShortName+" Projet : "+space.name ;
mail.execute(document);
64 REPLIES 64

mrogers
Star Contributor
Star Contributor
I don't think its supported.

mitpatoliya
Star Collaborator
Star Collaborator
You need to send mail in task-listner java class which will be invoked during transition.

rjohnson
Star Contributor
Star Contributor
The standard mail action does not allow attachments. You need to create a derivative. There is one on the internet which I downloaded and it works fine with 4.2c. My code is based on the code at http://savicprvoslav.blogspot.co.uk/2010/10/send-html-email-from-alfresco-33-with.html. Happy to share it with your but I can't attach it to this post so send me a message with an email address & I will forward it on.

jopdyke
Champ in-the-making
Champ in-the-making
Hi Bob,

I just started using Alfresco 4.1.5 (enterprise) and I have a requirement to send email with an attachment (from a workflow).  I would be very grateful if you could share you code with me.

My email address is james.opdyke@paceco.com

Thanks,
Jim

iomari
Champ in-the-making
Champ in-the-making
Greetings,
I'm  using alfresco 5. Will your solution work with this version? If so can you please send it to me?

[email]iomari@gmail.com[/email]

Thanks in advance

mvicidomini
Champ in-the-making
Champ in-the-making
Hello Bob thanks a lot for your help. latong06@gmail.com

rjohnson
Star Contributor
Star Contributor
Sent. Any issues, post here and I will do what I can

mvicidomini
Champ in-the-making
Champ in-the-making
Hello Bob , i'm sorry but i was to fast. I add a rule that will execute that will send an email with the document that has just been added.
The problem is that it execute a mail loop without end.
Please find my script below.

Do you see something wrong ?

Thanks in advance 

var PubDate = document.properties["cm:created"];
document.properties["cmSmiley TongueublicationDate"] = PubDate;
document.save();

var renditionDef = renditionService.createRenditionDefinition('cm:'+document.name, 'reformat');
renditionDef.parameters['mime-type'] = "application/pdf";
var pdfFile = renditionService.render(document, renditionDef);


var mail = actions.create("fg-mail");
var addresse = "admin@cip.mc";
var templateArgs = new Array();
var templateModel = new Array();
templateArgs['addressee'] = addresse;
templateModel['args'] = templateArgs;
mail.parameters.template_model = templateModel;
mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Notify Email Templates/notify_user_email_fr.html.ftl");
mail.parameters.subject = "Ajout de document";
mail.parameters.from = ANEMAIL;
mail.parameters.text = "Template has not been found. Please call Liberator support";
mail.parameters.node_to_attach = pdfFile;
mail.parameters.attachment_extension = "pdf"; 
mail.parameters.to = MYEMAIL;
mail.execute(document);

rjohnson
Star Contributor
Star Contributor
Well, I can't see a loop in your code for sure so I suspect that your rule is firing when the document is added and when the PDF is created as a rendition.

First I assume you have a rule that only fires when content is added to the folder. Nothing that fires on an update.

Assuming that is the case I suspect that Alfresco considers the creation of the rendition a "new" document (if you look inside the node browser it is a hidden child node of your document). If memory serves your PDF Rendition has a document type of cmSmiley TonguedfExport.

Looking at my code, I filter on document type and so this may be why I have never had this problem, so I would suggest you add code in your rule javascript like


if(document.typeShort != "cm:pdfExport") {
  …… execute your code
}


and see if that works.