Sunday, January 22, 2012

Sending attachment using Email Activity in BPEL 11g

Sending an attachment using Email Activity (in SOA 11.1.1.5) is an easy task. All you have to do is drag and drop an email activity and double click on it. Assign the following parameters and the attachment will be sent along with the email.
Name- Name of the attachment as it should appear
MimeType- This MimeType is for attachment. Choose appropriate MimeType from here.
Value - Write what you would like to see in the attachment. Simply hard coding.

Well, sometimes the requirement may be to send some custom data, may be you fetched some data at runtime from the DB and would lke to send it as attachment. This isn't complex either, all you have to do is modify the ContentBody parameter as follows. You can do this successfully from the EmailParamsAssign Activity but don't forget to verify the same in the bpel source too.


Extending this a bit further, if you'd like to send some files (image,pdf,doc,xls,csv) that are already stored at some server location or you may have written them from your process, follow these  steps.
1.) Set the appropriate MimeType for the file.
2.) Add the following line in the .bpel source under appropriate BodyPart.

3.) Add another copy operation in the bpel source to assign string('base64') to ContentEncoding in BodyPart[2].

4.) Modify the  ContentBody  parameter to read the file at runtime using ora:readFile() function as follows.


Key Points to Note:

  • The file location and name in ora:readFile() above are case-sensitive.
  • Specifying the correct MimeType is very important. If the MimeType is incorrect, either the mail won't go or you may get encrypted characters in the attached file.
  • file:/// (three slashes mean absolute path and two slashes mean relative path)

The above solution works with all the files. Should anyone need the working project, I can mail the same. 

53 comments:

  1. Hi,

    My name is suri. Nice to see this but bit difficult to go and do it in source level. So could you plz give me the steps in design view.

    Thanks
    Suri

    ReplyDelete
  2. Hi,

    Nice example. Can you pls post me the code @ crazypassionriders@gmail.com.

    Thnx

    ReplyDelete
  3. Hi,

    Very nice example.I have a requirement where File adapter read file as an attachment and need to send the same through email attachment.

    In this case the file is attaching in the mail but the content is not displaying is there a way to get it.

    Thanks,
    Ezhilan.
    Mail:ezhil3487@gmail.com

    ReplyDelete
    Replies
    1. Thanks Ezhilan!

      I haven't tried this but it must be around the content-encoding. I think File Adapter reads the attachment in binary. If somehow you can convert the binary content to base64, the solution should work.

      Let me know how it goes. I'll see to implement the same and will update here.

      Delete
    2. Hi Radha, good morning. i have same requirement..i have read the file from ftp and send the same as an attachment. but when i am reading the file as an attachment it is only giving me href number not the file attachment..can you please guide me how to resolve this. thank you

      Delete
  4. Hi!
    very good example
    but i want to read the file from a variable .......now to write
    "ora:readFile('file:////FILE_NAME.EXTN')"
    This correct........
    ora:readFile("file///bpws:getVariableData('inputVariable','payload','/client:process/client:attachmentURI')")

    ReplyDelete
    Replies
    1. Thanks.

      Concatenate the file name with 'file:///' using concat() function and then use that as a variable in ora:readFile() function. It should work.

      Delete
  5. Hi!

    very good example

    But want to read file location through an variable...

    How to read.......?

    ReplyDelete
    Replies
    1. Hi,

      You could concat the 'file:///' with your actual file location and pass that as a variable. It should work.

      Delete
  6. Hi Neeraj,

    Thanks for this post. Could you please upload this example bpel code here?

    ReplyDelete
  7. Hi Neeraj,

    Thanks for the useful post.
    Could you please let me know how to send the payload in xml format at the runtime when any fault occurs in bpel flow.

    Basically i what to send the input payload. PLease gimme your inputs

    ReplyDelete
  8. Hi,

    Thanks for your post.
    I am unable to use ora:readFile() function to get the content data. please help me.

    ReplyDelete
  9. Hi

    I need to use customize email template.Content of this template has images. how to do that

    Thanks

    ReplyDelete
    Replies
    1. For the help of others, you can reference the image in your HTML template as below and mail server will send the image too in the body.
      http://www.w3schools.com/html/html_images.asp

      Delete
  10. Hi:

    I was successfull in first part i-e., on setting the value of attachment in E-mail activity itself.
    But while try to do the second part i-e., sending a attachement from server location i not getting any mails. What i did was
    1)mime type is set to pdf/html (as it is a pdf file)
    2)placed the below contents under ConstructBody




    Code got successfully compiled but didnt get any mails.

    Note: I have ignored the base64 step as it throwed some error in my code like empty value is being passed.

    Regards,
    Bhaskar

    ReplyDelete
  11. Hi Neeraj,

    Actually I do have one scenario..where I have to read a xml file from one server location and send that xml as an attachment.

    Could you please send me your Email attachment example.
    Please send it on anu2anu@gmail.com

    Regards,
    Shweta

    ReplyDelete
  12. Hi Neeraj,

    Thanks for the post,it is hard to follow the steps without looking at the complete complete post, can you please attach your .bpel file to this blog or email it to me.
    Thanks,
    Jai.

    ReplyDelete
    Replies
    1. Sorry for that. Actually I am not able to upload the BPEL code here. However I can mail you the same. Please drop me an email and I'll do.

      Delete
  13. Any thoughts on sending jpeg files in email body from bpel...

    ReplyDelete
  14. Hi Neeraj,

    Nice post.
    My requirement is to send the rejected message file as an email attachment
    I have tried passing the values of the file path and file name to ora:read() but it is showing xpath exception.



















    Regards,
    Srijna

    ReplyDelete
    Replies
    1. These are the values passing in the email payload:



      Here I have created one variable for file path where I am providing absolute path for the rejected messages file location

      from expression="string('/d01/oracle/product/10.1.3/BPELTEST/bpel/domains/default/jca/TNVCatFPEDCategoryUpdate/rejectedMessages')"/>


      Here I have created another varirable file_name where I am concatenating file:/// and file path and filename along with extension

      from expression="concat("file:///",bpws:getVariableData('file_path'),bpws:getVariableData('inputVariable','payload','/ns1:RejectedMessage/@ns1:RejectionId'),".dat")"/>


      and finally passing file_name variable in ora:readfile function

      expression="ora:readFile(bpws:getVariableData('file_name'))"/>


      but getting the error saying that xpath exception:
      XPath expression failed to execute.
      Error while processing xpath expression, the expression is "ora:readFile(bpws:getVariableData('file_name'))", the reason is /d01/oracle/product/10.1.3/BPELTEST/bpel/domains/default/tmp/.bpel_FTPRejectionHandlerr_1.0_27e488a35296276ae6d9a3c88d6a2fc8.tmp/oracle.xml.parser.v2.XMLNodeList@d53378 (No such file or directory).
      Please verify the xpath query. Please check and reply.

      Regards,
      Srrijna

      Delete
  15. hi,
    I am getting the mail but without attachment.
    Please mail your code to me on srijna.saxena@gmail.com.

    Regards,

    ReplyDelete
  16. Hi Neeraj,
    Your explanition is quite simple. I was facing the same issue and would like to try this approach unlike using java embedding.Could you kindly mail to my id: mail2mybulk@gmail.com

    ReplyDelete
  17. Hello Neeraj,

    Nice one. I was able to implement the same , only difference is i am not reading physical file. Instead i am using an FTP adapter , read file as an attachment, then decode the content and send a file.

    But the only issue i am facing is with pdf and xslx files. I am able to successfully transfer rest of the files.

    Any pointer would be helpful.

    ReplyDelete
  18. Hi Neeraj,
    really a nice example. Can you please send me the code at debdeepmitra.in@gmail.com

    ReplyDelete
  19. Hi Neeraj,

    I am facing a problem.FTP adapter is reading a file opq format.Then it is converted to base64 with a decoder.Then the same is send as email attachment.
    Now this file is having special characters like 'Á'.In the attachment it is converted to '?'.Can you please help me out in this..

    Code Snippets
    ================================================================

    multipart/mixed














    =====================================================================




    ReplyDelete
  20. Hi Neeraj,

    Your post is really helpful in resolving one of long pending issue, but still i m struggling with encoding, could you please provide the code snippet oraclefusion4all@gmail.com

    ReplyDelete
  21. Hi Neeraj,

    Nice example. Can you pls post me the code @ nagarur.nitk@gmail.com.

    Thanks

    ReplyDelete
  22. Hi
    I am getting the mail but without attachment. pls can you post me the code @ nagarur.nitk@gmail.com


    Thanks

    ReplyDelete
  23. This comment has been removed by the author.

    ReplyDelete
  24. Hi Neeraj,

    Could you please send code to hrsh2002@gmail.com

    ReplyDelete
  25. Could you please send code to nagarur.nitk@gmail.com

    ReplyDelete
  26. Thanks, nice blog, it worked for me.

    ReplyDelete
  27. could u please mail the working project to ssoma.soa@gmail.com

    ReplyDelete
  28. Hi, Thanks for the useful post. Please send me the code to sugumarayyadhurai@gmail.com

    ReplyDelete
  29. Neeraj,
    Can you send the code to arun.arunramesh@gmail.com?

    ReplyDelete
  30. Can you send code to siram.rk@gmail.com

    ReplyDelete
  31. Hello Neeraj, please email copy of the code to silentevo@gmail.com? Thank you.

    ReplyDelete
  32. Dear Neeraj, Thank you for the useful post, could you please send the code to gural0112@gmail.com.
    10x.

    ReplyDelete
  33. FYI, with linux you will use readfile as follow:
    ora:readFile('file:////home/oracle/MyImage.gif')

    ReplyDelete
    Replies
    1. More details about email attachment on SOA suite:
      http://docs.oracle.com/cd/B31017_01/integrate.1013/b28981/notif.htm#BABDIDCJ

      Delete
  34. Hi. Thanks for your post.
    Its a great thing. But it would great if we could have a look at the code.
    Could you please send me the email of the BPEL code to jpriadharshini@gmail.com?

    Regards,
    Priya

    ReplyDelete
  35. hi neeraj,

    Can you please share the code to kumar.u.s.n@outlook.com. i used the same steps and in my process and i did a simple attachment text/html but i am not getting the mails.

    Thanks,
    kumar

    ReplyDelete
  36. Hi Neeraj, How are you ? Nice detail but I am facing some minor issue. Is that possible for you to share the code at gohbk2003@gmail.com. Thanks in Advance

    ReplyDelete
  37. Hey buddy, i would like you help us, we are trying to attach one pdf in Human task, the problem is when it's sended to IOS Devices, the app mail show clip (attach) but we can't see it but when we create a email component and attach a pdf, it can see in the IOS devices, i can see that the email component have MIME 'multipart/mixed' do you have any suggestion?

    Regards.

    ReplyDelete
  38. This comment has been removed by the author.

    ReplyDelete
  39. Hi,

    Nice example. I am facing an issue while sending the csv file as Email attachment. I am able to send the email with csv file but file content is not printing in the file.Can you pls post me the code @ hari.mandadapu@gmail.com.

    Thnx

    ReplyDelete
  40. Hi Neeraj

    Thanks for providing such a Nice Post. I have one requirement of polling a file and sending the same file as attachment to mail. Can you please let me know whether have u tried that approach and also please provide the Code to my email : prtpkrishna@gmail.com

    Thanks
    Pratap.

    ReplyDelete
  41. Nice post...

    How can I send multiple files as an attachments to a single receiver through Email.

    ReplyDelete
  42. Hi Niraj,

    In SOA12c am writing the file "WorkdayEmployee.csv" into one location (Example: /tmp). In the same BPEL process i have to send the generated file as an attachment to my email id. Could you please help me out. I have gone through the the code which you have mentioned. But am not sure where to add that snippet. If possible can you share the code base to my email address santhosh.kumar49@gmail.com and let me know your number to call you if you permits.

    Regards,
    Santhosh Kumar. K

    ReplyDelete
  43. Hi. can you please send the code at vipaldua@gmail.com

    ReplyDelete
  44. H, can you send the source code to pappu229@gmail.com

    ReplyDelete
  45. This comment has been removed by the author.

    ReplyDelete