Free Support Forum - aspose.com

Mailing with docx template

hi out there,
i need some help find the best solution for my app. so here are the facts:

my client shoud upload a final docx template with merge fields,images etc. to do some mass mailing.

the template contains some nested regions (if i got that right there is no way to handle this directly with aspose words so i had a try with a solution from sourceforge AdvancedMailMerge http://advancedmailmerge.codeplex.com/ and this works for me)

now there are a lot of images in the doc file and each time when i save the document to a new stream as html all the images are created again.
i came up with the idea to export the template once as html and store the result in the database. this way it should be a bit faster anyway instead of handling the files everytime to create a new email.

my problem now is to get back the mergefields from html to run the MailMerge with the final html. there is another post in here doing the same and this solution seems to work. Preserving mergefield in html format

but now with this solution there is a problem with the nested tables. somehow these regions are duplicated and the final result is not what i expected.

looking around a couple of hours i’m not sure if i’m following the right idea. so perhaps you can give an advice how to handle the situation in good way.

is there a chance to stop the image export each time. just do it once and reuse the same image for the next export to stream?
is it a good idea to store the html export in the db (performance issues) and how can i get back the mergefiled when loading the Document from the html file without the problems of duplicated regions?
is there another way i missed to create html output?

thanks for your time and greetings from germany

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Why do you save your template in your database as HTML? Maybe you should store template you the database in Word document format (DOC, DOCX, RTF or WML). In this case, you do not need to worry about preserving merge fields.

Then, when you need to send emails, you just get template from database, fill it with data and send already filled document to your clients. I think the following article could be useful for you.

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/howto-convert-a-document-to-mhtml-and-email.html

Best regards.

hi, thanks for the response.
i was not working on this topic since then. now i have the time to go on and my problem is still not solved.

even if i follow your suggestion i’m running in the same problem again. at the moment the document is saved to html, the images will be saved to the disk or to a stream. i could handle them in a memorystream but this solution is a workaround as well and will cost a lot of performance on a huge application with a lot of emails and templates.

so to make my thoughts clear i will describe the situation again.

i’ve got the gui to upload the word template. when the upload is finished i’m able to handle the images in the template once. so the result is a template and an folder with the images i need. now there will be a lot of templates and a lot of images. if i got it right the images will be created each time again when i store to doc to html. this is not needed. is there no way to reuse the images created the first time?

think about really a lot of emails so that is no option to handle the disk i/o. i just want to replace the images in the html with the existing once. set an absolut path to my server. thats all. just replace the images with an . the images will only change if there is a new template and this will be handled directly after the upload.

i tried a lot of things but it seems that there is no way to stop the default image handling from aspose. i know how to replace the images in the html result already and i’m able to use the same path for all my emails but i’m not able to stop aspose from saving the images again. at the moment they are saved to a temporary location, replaced in the html with the once first created and deleted again. this is not a really nice way to to do this and makes no difference in performance issues.

do i miss something?

thanks a lot for your response

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Maybe in your case, you can try replacing images in the template with placeholders (simple text like <%HERE_WILL_BE_IMAGE%>) and then after converting document to HTML, you can replace these placeholders with tags. But I do not like such approach a lot. First of all, you should somehow know which of placeholders replace with which of images. Second, you should post-process your documents. Third, merge fields are not preserved after converting document to HTML, so you need to work around this somehow or store only final documents in Data Base.

From my point of view it is better to store templates as is, i.e. in MS Word format. So the simplest way, which your template come from uploading to sending to the end user is the following:

1. Upload template and save it into database as BLOB.

2. Get template from database and execute mail merge to fill it with actual data.

3. Save output document in MHTML format and send to the end user as described here:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/howto-convert-a-document-to-mhtml-and-email.html

Here you can find a simple code example, which shows how to save/read document from Data Base:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/howto-load-and-save-a-document-to-database.html

Hope this could be useful for you.

Best regards.

ok this is an option. i will giv it a try.

mhtml is no way for us at the moment. and i forgot to speak about the different usages of the final html. we do not only want to send emails. there is another application for printing the html result.

so perhaps your first suggestion will fit for us.

many thanks. i will give you some feedback about the result.

Hi Daniel,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Hope the suggested approach will fit your needs. I just would like to add that you could use Aspose.Words to print your documents. Please see the following link for more information:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.document.print_overloads.html

Best regards.