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

rjohnson
Star Contributor
Star Contributor
So if I understand, when you remove the code above the rule doesn't recognise "document" as existing?

If this is so then I think you have a deeper problem here because "document" always exists in a rule and points to the "document" you have just created.

Are you sure that your issue is not with the template trying to use document.properties["cmSmiley TongueublicationDate"] and failing because that does not exist (or is null)?

What error do you actually get?

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


when i use var pdfFile = document.transformDocument("application/pdf", userhome); it creates correctly the file in the userhome.
But mail.parameters.node_to_attach = pdfFile does not retrieve anything i mean there is no attachment to the email.

Thanks.

mvicidomini
Champ in-the-making
Champ in-the-making
I am also trying to use mail.parameters.node_to_attach = document.nodeRef;
but it does not work

rjohnson
Star Contributor
Star Contributor
The document.nodeRef won't work you need to send it the object but I am baffled as to why pdfFile doesn't work. All I can say at this moment is that when I get a chance I will test it out (I'm running 4.2c) and let you know because so far as I can see, it really should work and, in principal I do the same thing regularly.

Are you using SOLR indexing or Lucene?

mvicidomini
Champ in-the-making
Champ in-the-making
SOLR

Thanks again for all your help

francesco_lilli
Champ in-the-making
Champ in-the-making
Hi rjohnson,
could you please send me your code? My mail is francesco.lilli [[_AT]] gmail [[_DOT]] com
Thank you very much Smiley Happy

Francesco

In your email.

ritchiewhitemor
Champ in-the-making
Champ in-the-making
Hi rjohnson,
could you please send me your code? My mail is RichiB@yandex.ru

Ritchie

Its in you email.

instalaciones
Champ in-the-making
Champ in-the-making
I use the savic´s solution but it´s generate errors in others js processor.
Can you snd me your solution?
My mail is instalacionesdepuertas@gmail.com

Thanks