cancel
Showing results for 
Search instead for 
Did you mean: 

Create a custom document from incoming email (SMTP)

sam4alf
Champ in-the-making
Champ in-the-making
All,

I've successfully configured SMTP for receiving emails in to a folder. When I send a text email to <folderID>@host.com, I do see the document getting created inside the folder. It's not in proper format though.

What I really need is that the email attachment should be treated as content and body part of the email has properties. Using these, I want to create a custom document inside the folder.

I created a JS file and created a rule to call this JS on document entry. Somehow, it doesn't seem to work.

Here is my code:

<import resource="/Company Home/Data Dictionary/Scripts/command-utils.js">

function processCommand()
{
   var isEmailed = document.hasAspect("emailserver:emailed");

   logger.log("Command Processor: isEmailed=" + isEmailed);

   if (isEmailed)
   {
      var attachments = document.assocs["attachments"];
     var subject = document.properties["cm:title"];
      if (attachments != null)
      {
         for (var i = 0; i < attachments.length; i++)
         {
                      var randomNumber=Math.floor(Math.random()*99999999);
         var doc = space.createNode(randomNumber + ".tiff", "namespace:custom_document");
         doc.content = attachments[i];
         doc.mimetype = "image/tiff";
         doc.properties["namespace:attribute1"]=subject;
         doc.save();
         }
      }
   }
}

processCommand();

What am I doing wrong?

Thanks for your time and suggestions.

-Sarma.
2 REPLIES 2

mrogers
Star Contributor
Star Contributor
A better approach may be to add your own Java EmailMessageHandler, that does what you want in the first place rather than letting the default handler do the wrong thing and then trying to clean up afterwards.

I don't think your approch for generating the name with a random number is sound.

sam4alf
Champ in-the-making
Champ in-the-making
Hi,

Thanks for your reply and suggestion. The naming part is just for testing and we have an elaborate naming standard based on several metadata fields.

If I have to write a java message handler, can the same handler serve/listen to/create several custom types of documents? Or is the handler tied to one incoming email address and one type? I would rather prefer the latter approach if that is possible.

Please throw some light on this. Thanks.

-Sarma.