Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2004, 01:18 AM
Registered User
 
Join Date: Jul 2004
Location: Sydney, NSW, Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending email using word template and DB

Hi,

I want to create and send emails to various people's details from a database and using different word templates based on the catergory of the people belong to. The word templates will have many variable to be inserted from the database. The code to generate will be asp cdo.

TIA
Tissa
 
Old July 7th, 2004, 01:38 AM
Friend of Wrox
Points: 1,288, Level: 14
Points: 1,288, Level: 14 Points: 1,288, Level: 14 Points: 1,288, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: Stockholm, Sweden
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

You mean that you can send mail to different addresses which are in your database for getting their details and send mail to them


eg

<%
strSQL2 = "Select * from Contacts "
    set objRS2 = objDataConn.execute(strSQL2)
Set myMail=CreateObject("CDO.Message")
myMail.Subject=objRS2(Subject)
myMail.From="Your adress"
myMail.To=objRS2(address)
myMail.TextBody=objRS2(message)
myMail.Send
%>


Cheers :)




Love 4 all
 
Old July 7th, 2004, 01:55 AM
Registered User
 
Join Date: Jul 2004
Location: Sydney, NSW, Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for that qazi_nomi,

Actually I want to use a Word Template and the Database.
I have done emails with database parameters.
Now I need to use Word Templates...

Any help appreciated.

TIA
Tissa
 
Old July 7th, 2004, 02:04 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

The easiest method is to

1) convert the word template to html tremplate.

2) insert template variables into html file. You may define tags for this. For e.g. [currentdate] may be one variable. [bookingnumber] may be another variable.

3) read the template into a string.

4) Now, open database. Traverse through records.

5) For each contact, replace the template variables with appropriate values. The function Replace will be of help in this case.

6) You can set this string as the value of HTMLBody property of cdo object.

Please take care not to have the variables as part of the other content of template. The delimiters may be chosen appropriately.
 
Old July 7th, 2004, 02:18 AM
Friend of Wrox
Points: 1,288, Level: 14
Points: 1,288, Level: 14 Points: 1,288, Level: 14 Points: 1,288, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: Stockholm, Sweden
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

If you want to send the word templates as a attachment then simply send

myMail.AddAttachment "c:\mydocuments\yourfile.doc"


Love 4 all
 
Old July 7th, 2004, 03:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Tissa,

Some minor changes I would add to the one suggested by Madhu.

1) convert the word template to html template. May be you can name it as template1.txt / template1.asp / template1.csv / template1.html itself

2) insert template variables into html file. You may define tags for this. For e.g. [currentdate] may be one variable. [bookingnumber] may be another variable.
You can as such use ASP variables instead of User defined TAGs.
Eg:
Dear <%=RsObject("FName")%> <%=RsObject("LName")%>,
            OR
Response.write "Dear " & RsObject("FName") & " " RsObject("LName") & ","

3) Read the template into a string. using FileSystemObject

4) Now, open database. Traverse through records. If needed, do a response.write of the string read from template, to see if data got substituted in relevant places.

You can avoid doing a replace mentioned in this step, as everything is in place after using ASP variables in the template.
5) For each contact, replace the template variables with appropriate values. The function Replace will be of help in this case.

6) You can set this string as the value of HTMLBody property of cdo object.

Everything else is the same.
Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old July 7th, 2004, 11:37 PM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

Helo Vijay,

Yes. This method is much more efficient that mine. This helps me also as I am doing a similar work now.
 
Old July 7th, 2004, 11:39 PM
Registered User
 
Join Date: Jul 2004
Location: Sydney, NSW, Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for madhugv and happygv for the excellant answers.

and happygv for giving the sample code bits.

Tissa




Similar Threads
Thread Thread Starter Forum Replies Last Post
Unstable VBA in Word Template keytecstaff Word VBA 1 June 5th, 2006 03:47 PM
passing values into word template narendrapawar VB How-To 1 April 5th, 2005 12:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.