View Full Version : Email system based on ASPEmail
dominicall
11-08-2002, 07:45 PM
Hi all.... a little help required...
I've developed an email system for a client that allows them to send email (multipart HTML and text only from the site) using the Persits ASPEmail component.
The component allows two methods of adding the body/alt-body.
The first is direct entry of the data in the page, i.e....
Dim strBody
strBody = "<HTML><HEAD></HEAD><<BODY>"
strBody = strBody & "<p>Some text here" .... etc....... you get the drift.
The second is through the following method which will take the body from a file uploaded on the web server.
Mail.AppendBodyFromFile "c:\dir\subdir\filename.htm"
Both techniques work fine, but so far as I can figure out only the first allows the personalisation of the message from the recordset being mailed, i.e.
strBody = strBody & "<p class="text">Dear " & rs("firstname") & "</p>"
I've tried putting the rs("firstname") in the remote file but it isn't parsed by ASP (???).
While I could continue to use the first method to achieve the personalisation, it does allow for potential problems once I release the app to the client if he makes a mistake. Using the second method means all he would have to do is to select the HTML and text files I'll have uploaded to the server and press the 'Send Email' button.
Anyone got any ideas how I might achieve this???
Thanks
Dominic
Mhtml
11-09-2002, 07:30 AM
Ok, no one else has replied so I may as well have a go at it.
I'm not quite sure if I get what you want to do but why don't you put rs("firstname") in a variable before you construct the email?
Eg;
dim strFirstName
strFirstName = rs("firstname")
Then build your email.
oracleguy
11-09-2002, 07:52 AM
If you want the asp code in the text file to be parsed by asp, you are going to have to read the contents of the file first. You have to use the FileSystemObject (http://www.w3schools.com/asp/asp_ref_filesystem.asp) to do this. Then I guess you'd have to find where you refered to the recordset inside the file and have it replace it with the the values from your recordset.
You can use the 'replace' command in ASP to replace the values.
I hope this makes sense. :)
dominicall
11-09-2002, 08:37 AM
Hey oracleguy
I'd been thinking along the same lines but was too tired last night to figure it - but have got it working now.
I'll post the full code up when I get the time but for anyone who's interested and can work out the full thing themselves you can use the following.
Dim objFSO, objTextStream, objTextStream2
'set the objects to get the file from the server
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFSO.OpenTextFile("c:\inetpub\wwwroot\agents\test\testtstream.htm")
Set objTextStream2 = objFSO.OpenTextFile("c:\inetpub\wwwroot\agents\test\testtstream.txt")
'put the replacement recordset values into variables
Dim strName
strName = rs("firstname")
'get the file using read all
'strDoc is the HTML email version
'strDoc2 is the text version
Dim strDoc
strDoc = objTextStream.ReadAll()
strDoc2 = objTextStream2.ReadAll()
' Replace the [Name] placeholder in the template
strDoc = Replace(strDoc,"[Name]",strName)
strDoc2 = Replace(strDoc2,"[Name]",strName)
Mail.Body = strDoc
Mail.AltBody = strDoc2
Mail.Send
objTextStream.Close()
Set objTextStream = Nothing
Set objFSO = Nothing
I'm assuming that this will work with all email components that support multipart/alternative format emails.
Once I've built the full thing and tested it I'll post it up here and ppl can use it.
Dominic :D
ps. I sent a support email to Persits as well to see if they had a solution... this is what I got back...
No, not really. When you call AppenbdBody fromFile, the content of the file is copied inot mail.Body. Templates are not supported this way.
Not espcially helpful - LOL
Mhtml
11-09-2002, 10:54 PM
Ahhh, I get it now. My head wan't on straight.
.....
Can't help though, :(
dominicall
11-09-2002, 11:00 PM
Hey oracleguy
I'd been thinking along the same lines but was too tired last night to figure it - but have got it working now.
I'll post the full code up when I get the time but for anyone who's interested and can work out the full thing themselves you can use the following.
Dim objFSO, objTextStream, objTextStream2
'set the objects to get the file from the server
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFSO.OpenTextFile("c:\inetpub\wwwroot\agents\test\testtstream.htm")
Set objTextStream2 = objFSO.OpenTextFile("c:\inetpub\wwwroot\agents\test\testtstream.txt")
'put the replacement recordset values into variables
Dim strName
strName = rs("firstname")
'get the file using read all
'strDoc is the HTML email version
'strDoc2 is the text version
Dim strDoc
strDoc = objTextStream.ReadAll()
strDoc2 = objTextStream2.ReadAll()
' Replace the [Name] placeholder in the template
strDoc = Replace(strDoc,"[Name]",strName)
strDoc2 = Replace(strDoc2,"[Name]",strName)
Mail.Body = strDoc
Mail.AltBody = strDoc2
Mail.Send
objTextStream.Close()
Set objTextStream = Nothing
Set objFSO = Nothing
I'm assuming that this will work with all email components that support multipart/alternative format emails.
Once I've built the full thing and tested it I'll post it up here and ppl can use it.
Dominic :D
ps. I sent a support email to Persits as well to see if they had a solution... this is what I got back...
No, not really. When you call AppenbdBody fromFile, the content of the file is copied inot mail.Body. Templates are not supported this way.
Not espcially helpful - LOL
Roelf
11-10-2002, 06:43 AM
And what if you use that AppendBodyFromFile, the file is copied into the body property, then you can do your replace function on that property. I think that is much faster than to use the filesystemobject first
dominicall
11-10-2002, 07:35 AM
Doesn't work - that was the very first thing I tried.
Other thing I'm thinking about is to use the FSO to put the contents of the text files into the database and retrieve them when I need them - am going to test both ways and then load test the app on the server. Don't think it will make much overall difference either way but one I've done it I'll let you guys/gals know.
Dominic :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.