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

mvicidomini
Champ in-the-making
Champ in-the-making
Does not work , it is still looping

rjohnson
Star Contributor
Star Contributor
Does it repeatedly email the same thing?

mvicidomini
Champ in-the-making
Champ in-the-making
Yes unfortunatly

rjohnson
Star Contributor
Star Contributor
Can you try using the standard mail object and just mail yourself a message. If that loops its a problem with the rule trigger. If not then its something to do with the fg-mail object but I cannot think what as near enough I do exactly what you are trying to do and it works fine for me.

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

i have already try with the simple email notification and it work fine. Maybe it is a problem with my script ….

Do you have any advise ?

Thanks

rjohnson
Star Contributor
Star Contributor
Honestly your script looks fine, and I do more or less the same thing as you and it works well for me. The difference is that I look for specific document types and only email PDF's of those whereas I assume you will email a PDF for any document type.

I can only assume that the creation of the rendition is causing the script to trigger over and over and the document type of the rendition is not cmSmiley TonguedfExport - it may well be cm:content in which case a PDF rendition and your original document will be indistingushable.

One thing to try would be this

replace


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


with


var pdfFile = document.transformDocument("application/pdf", userhome);


This will create the PDF document in userhome which (I presume) is not covered by your rule (if it is create the PDF somewhere that isn't).

If that doesn't work I am at a loss, but please let me know as I will test it on my own installation and figure it out because this is important to me.

mvicidomini
Champ in-the-making
Champ in-the-making
Still looping, but the thing i that if i do not apply the rule the the subfolder it works fine. As soon as i apply it on the subfolders it is at this moment that the mail sending is looping.

thanks again for all your time.

rjohnson
Star Contributor
Star Contributor
Well, it sounds like somethings hapening in your sub folders. Do you have any other rules?

mvicidomini
Champ in-the-making
Champ in-the-making
Nothing, it is a fresh install …

mvicidomini
Champ in-the-making
Champ in-the-making
I found the mistake, it is link to

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

Because as soon as i removed it the mail stop looping but i cannot retrieve the file to attach to the email anymore.
So , how can i retrieve the referenc of the document that has just been added 

Thanks again