Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello Guys,


I am facing below problem related to Email-Body,

I want to create Email-Body dynamically not static,
my scenario is,
I want to send some records to another person,i.e. Top 10 records.
and i an retrieving records from database but IF in DB there is present only 5 records then in Template it is replacing only 5 records and other 5 display templates hardcoded value,
so i want to avoid this things,

My templated will be decided on Database records when my record is 5 then it will fill in email body with 5 records and if 10 then 10 record table.

Please suggest me what i do in that case.
Posted
Comments
Mohd. Mukhtar 26-Dec-12 4:44am    
What have you tried?
madhuri@mumbai 26-Dec-12 7:05am    
nothing i have tried,becoz i don't know any idea...
but after Robot solution I have tried using strngbuilder,and it is done,but i don't understand his way i.e. using html file.

You can generate HTML Table Tag completely from the code. Traverse through the records and keep adding tags whith data in
tag.

You can use StringBuilder for this.

If there is much more content above and below the table. I suggest u to create a html template file and put some Key element like [Table] and use the IO operations to read the file and replace [Table] text to dynamicaly generated html table text and then send the complete html as email (by setting HTML mail body)
 
Share this answer
 
Comments
madhuri@mumbai 26-Dec-12 7:49am    
Thanks,
I have tried this ,It is done.
But i have added it in code,Can i do this all these things taking template from DB.. i.e. in future my email body will change then that time its DB level changed occured.
Rakesh6906 26-Dec-12 8:23am    
Yes, there are multiple ways..
You can store the entire HTML in a table(which i said in File before) and can use the same replace string concept...if required :)
madhuri@mumbai 31-Dec-12 2:09am    
Can i used here Css in html
Rakesh6906 31-Dec-12 23:31pm    
Yes you can.
You can loop through the datatable and use StringBuilder[^] to dynamically create the email body.
You can refer datatable-foreach Loop[^] for information on how to loop through all the elements in the DataTable
 
Share this answer
 
Comments
madhuri@mumbai 26-Dec-12 7:53am    
Thanks.
__TR__ 26-Dec-12 8:47am    
You're welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900