Read file to create an email from

Hello,

I hope someone will be able to help me.

I would like to build a service which will process files saved to a folder. This file will contain the email address, email subject title and the body text (with html tags). I would like my service to send read the file and send the email.

I know how to use the smtp function and I know how to get the file name from the folder, but how do I get at the contents of the file?

Any suggestions would be welcome.

Thanks,

Gill

Gill,

In order for you to be able to read the contents of your files as ‘Email-Id(s)’, ‘Subject’ and ‘Body’, you will either need to create that file as a flat file (ie use delimiters) or make it into an XML file (I like XML!!!). Then you can use the pub.file:getFile to get the file and convert it into an IS Document using appropriate parsers - for flat file, depending on the way you have delimited it, you might have to write a service to do this or you might use convertToValues if you have a schema configured flat file. If you are using XML file you can convert the file into an IS document using getFile->xmlStringToXMLNode->xmlNodeToDocument.

Once you have the IS Documents with fields containing ‘Email-Id(s)’, ‘Subject’ & ‘Body’, it will be a piece of cake.

HTH, Rohit

Gill,

Were you able to resolve your problem? Just wondering!

Rohit

Rohit,

Yes I did solve my problem. I got the contents of my txt file using getfile and then converted the bytes into a string using bytestostring. I couldn’t find out how to extract the email address from my txt file as I was using the contents as the body text of the email so obviously I didn’t want the body text to contain the email address. So I ended up creating a separate file to hold the email address with the same filename as the other txt file in a different folder.

Gill

Gill,
I am glad that you were able to solve the problem. It might be reasonable for the sake of performance to have all the stuff in just one file - just have it delimited. You can use the same first two steps to get the file and convert it into the string and thereafter you can ad pub.string:tokenize to break the ‘string’ output from bytesToString into three different pieces of information ie email id, subject, body text. Here’s one of the way to store all three pieces in the same file:

someOne@WmUsers.com#$This is a sample mail#$This is the body text…

Now while using the pub.string:tokenize, give # as delimiter and you will get a stringList (valueList) with email-id at 0 pos, subject at 1 and the body at 2. Loop over this valueList and map the required field depending on the iteration of the loop. One thing you will have to be careful about is choosing a delimiter (in the example above I've used #, you can choose a combination that suits your need). Though it shouldn’t happen, yet if you are not sure that the delimiter that you want to use will not appear in the body text or subject line… then I guess you can continue with your current approach.

Rohit