Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

email message body 1

Status
Not open for further replies.

scribbler

MIS
Feb 4, 2002
206
GB
Please can anyone point me in the right direction.
I have managed to make my pages send HTML emails to members in my database with hardcoded message body but what I am hoping to achieve is to be able to have a standard heading page and then construct a seperate html page and using something like #include bring the 2 together in the body of the email just like companies do when they send out advertisements. other than that I presume I'd have to just use an attachment.
 
Yep That sounds like the correct way to do it or you can have a predefined template page with place holders ( [username] [firstname] etc) in the body, then open it as a string with the FSO and replace the placeholders with the appropriate info before sending it as objMail.HTMLBody.



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Thanks for taking time to reply Chris but... yep there's a but again.. I'm fairly new to this ASP lark and am not sure what you mean by open it as a string with the FSO. I only mentioned #include as I've seen it used before. Are you saying that in the HTML body of my template I could use the #include command. Im not sure wht you mean by FSO either.. Sorry

 
Try something like:

<%
Dim myMail
Set myMail = CreateObject("CDONTS.NewMail")

Set myHtmlSystem = Server.CreateObject("Scripting.FileSystemObject")
Set myHtml = myHtmlSystem.OpenTextFile("d:\emailfile\html\template.html",1)
HTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & NL

script = myHtml.ReadAll

myMail.From = "you@isp.com>"
myMail.To = "them@isp.com>"
myMail.Subject = "Test"
myMail.BodyFormat = 0
myMail.MailFormat = 0
myMail.Body = HTML & script
myMail.Send

%>
 
Thankx mbiro but can you please enlighten me a little on parts of the code and to what their function is. Ive left the items out that I am familiar with but as you can see that doesn't account for much;

Set myHtmlSystem = Server.CreateObject ("Scripting.FileSystemObject")

Set myHtml = myHtmlSystem.OpenTextFile("d:\emailfile\html\template.html",1)

HTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & NL

script = myHtml.ReadAll
myMail.Body = HTML & script
 
I added comments. My string names, script and HTML, are probably not the best names...kinda confusing.

<%
Dim myMail
Set myMail = CreateObject("CDONTS.NewMail")

Set myHtmlSystem = Server.CreateObject("Scripting.FileSystemObject") ' This creates an object that can read files on the server
Set myHtml = myHtmlSystem.OpenTextFile("d:\emailfile\html\template.html",1) ' This is where you load the file located at the stated path into the object previously created
HTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & NL 'This is probably not necessary, maybe just considered best practices

script = myHtml.ReadAll ' this sets a string to contain all of the text in the file previously loaded

myMail.From = "you@isp.com>"
myMail.To = "them@isp.com>"
myMail.Subject = "Test"
myMail.BodyFormat = 0
myMail.MailFormat = 0
myMail.Body = HTML & script 'This is where you set the body of your email to be the strings from above.... like I said, you can probably ignore the HTML string. The string "script" is the important one
myMail.Send

%>
 
Hi mbiro

It appears that I cannot use your code as I have to use CDOSYS on the host server. Hope you can help it's driving me nuts... My code so far is as follows;


Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

objCDOSYSCon.Fields(" = "THE IP ADDRESS"
objCDOSYSCon.Fields(" = THE PORT No
objCDOSYSCon.Fields(" = 2
objCDOSYSCon.Fields(" = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon

objCDOSYSMail.From = Request.Form("emailaddresstxt")
'objCDOSYSMail.From = "fromAnyone@test.co.uk"
objCDOSYSMail.To = "ToAnyone@test.co.uk"
objCDOSYSMail.Subject = "Website contact"

'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
objCDOSYSMail.HTMLBody = Request.Form("emailaddresstxt") & " Has registered to recieve advert bulletins"
objCDOSYSMail.Send
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
 
This should work for you:

<%
Set myHtmlSystem = Server.CreateObject("Scripting.FileSystemObject")
Set myHtml = myHtmlSystem.OpenTextFile("d:\emailfile\html\template.html",1)
HTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & NL

script = myHtml.ReadAll

Dim objMail
'Create the mail object
Set objMail = Server.CreateObject("CDO.Message")

'Set key properties
objMail.From = "you@isp.com"
objMail.To = "them@isp.com"
objMail.Subject= "Subject"
objMail.HTMLBody = HTML & script

'Send the email
objMail.Send

'Clean-up mail object
Set objMail = Nothing
%>
 
Hi again mbiro

I Tested your suggestion but keep getting the following error;

Microsoft VBScript runtime error '800a0035'
File not found
/testadvert.asp, line 87

The line 87 refers to the following line;
Set myHtml = myHtmlSystem.OpenTextFile("Advert.html",1)
I presume it's an error with the location of my stated file. I have tried ../ ./ etc but still same reply. Do you have any idea what may be causing this ?

I've included my code again just incase something else is the cause.




Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

objCDOSYSCon.Fields(" = "IP Address"
objCDOSYSCon.Fields(" = Port No
objCDOSYSCon.Fields(" = 2
objCDOSYSCon.Fields(" = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon

Set myHtmlSystem = Server.CreateObject("Scripting.FileSystemObject")
Set myHtml = myHtmlSystem.OpenTextFile("Advert.html",1)
HTML = "<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & NL
script = myHtml.ReadAll
Dim objMail
'Create the mail object
Set objMail = Server.CreateObject("CDO.Message")

'Set key properties
objMail.From = "from@test.com"
objMail.To = "to@test.com"
objMail.Subject= "Test Advert"
objMail.HTMLBody = HTML & script

'Send the email
objMail.Send

'Clean-up mail object
Set objMail = Nothing

Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
 
You need to turn your effectively-virtual path into a physical path, using Server.MapPath like this:
Code:
Set myHtml = myHtmlSystem.OpenTextFile(Server.MapPath("Advert.html"),1)
 
Hi Genimuse

I'm not sure I'm following all of this code but I did as you suggested

Set myHtml = myHtmlSystem.OpenTextFile(Server.MapPath("Advert.html"),1)

But still get the same error;
Microsoft VBScript runtime error '800a0035'
File not found
/testadvert.asp, line 87

 
Hmm. Assuming that the HTML file is in the same directory as the ASP page this script is on, perhaps you need to specify the current directory by adding ./ to the beginning of the file name:
Code:
Set myHtml = myHtmlSystem.OpenTextFile(Server.MapPath("./Advert.html"),1)
 
Is Advert.html in the same directory as the asp page calling it?

If you do a response.write Server.MapPath("Advert.html"), is the path correct? (Comment out the offending code and put this response.write in so the page will display where it is looking for the file.
 
I did the code change as suggested e.g.

'Original code Replaced
'Set myHtml = myHtmlSystem.OpenTextFile(Server.MapPath("Advert.html"),1)

'New code Line
response.write Server.MapPath("Advert.html")

But still the same error message....

Microsoft VBScript runtime error '800a0035'
File not found
/testadvert.asp, line 87
 
I am sorry I was unclear. Comment out all of your asp code except the response.write Server.MapPath so that the browser will display the path. The respons.write is only to help find the error. Your browser should display something like 'C:\inetpub\site\Advert.html'

Or, just make a test.asp page that contains only:

<%
response.write Server.MapPath("Advert.html")
%>

and run it. Does it display the proper path to the advert.html file?
 
Back again mbiro..

I used the physical path that you mentioned as below, but then got a different error (but should I class this as progress ??

CDO.Message.1 error '80040220'
The "SendUsing" configuration value is invalid.
/testadvert2.asp, line 39



Set myHtml = myHtmlSystem.OpenTextFile("C:\Program Files\Ensim\Sitedata\webppliance\conf\domains\elfsales\Inetpub\
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top