Click to See Complete Forum and Search --> : Sending an email via an access database


Metroid
02-20-2004, 03:39 PM
What I need to do is when a user wants to download a file they will click on the driver/file. Once clicked, they will be taken to a form page where they will enter their e-mail and name. Once they click the form page...this information will be entered into a database. [All in one action]. Once the information is entered into a database, they will be sent an e-mail with a link to the desired file.

I am a little stuck on how to do this. If anyone has a clue, any information will be much appreciated.

Thanks-in-advance

buntine
02-21-2004, 10:47 AM
Set up an HTML form with the relevent controls. Textboxes, submit buttons, etc.

Once the user has filled out the form, have its data sent to an ASP page named storeDate.asp, for arguments sake.

In storeData.asp, set up a database connection and store the correct info in a table of your choosing. In this example i will use a table called 'users' which contains two data fields, 'username' and 'emailaddr'.


response.buffer = true
dim strEmail, strName '|Dimension variables.

'|Define local variables.
strEmail = request.form("txtEmail")
strName = request.form("txtName")

'|Check for null entries.
if isEmpty(strEmail) or isEmpty(strUser) then
response.redirect(request.serverVariables("HTTP_REFERER"))
end if

'|Construct SQL query.
sql_query = "INSERT INTO users (username, emailaddr)"
sql_query = sql_query & " VALUES ('"&strName&"','"&strEmail&")"

conn.execute(sql_query) '|Execute query.


conn.execute(sql_query) - this line will execute the SQL query. Ensure your connection object is named 'conn'.

Next you will set up an email object using a relevent ASP component. CDONTS, CDO and ASPEmail are among the most commonly used components. Make sure your server supports atleast one third party email component.

www.aspemail.com - ASPEmails site.

Regards,
Andrew Buntine.

Metroid
02-23-2004, 11:05 AM
Thanks for the response. I don't think I was very clear in what I need help with. I can make all the connections and send post to the database. What I need some direction on is how to grab the response from the database and send via an email. But before a response from the email can be sent, I need to generate some sort of random algorithm where the user receives an e-mail that directs the user to a download location for the document requested. The reason that the company wants this done is to reduce competitors from downloading their items off of the web. But they don't want to place any sort of password protection on the files, because this is a public site.

The second part that I'll need help with is to have some sort of javascript that is going to check from a list (an array, maybe) of predetermined domains (competitors) that aren't allowed to download material.

Any direction(s) will be much appreciated.

Thanks-in-advance.

buntine
02-23-2004, 12:26 PM
Ok, so you want to grab an email address (among other things) from your database and then send that user an email?
Also, what will the random algorithm consist of?

Sorry for the misunderstanding, its often hard to tell what people want when you cant speak face to face.

Regards.

Metroid
02-23-2004, 01:51 PM
Lets see...starting from the begging. When a user requests a document, they will click on the document…this will transfer them to a form page…while grabbing the document title that they want and displaying on the form page. The user will enter their email address and hit submit.

(The actions once the user clicks submit):
The email address and the document title will enter into the database. A predetermined list of domain names will be checked, if a given domain name is in this list then the person will not receive an email [not sure if want to let them know that], but this request for information will be recorded in the data-table. If the domain name isn’t in the list of blocked domain names, then – as with the blocked domain names – their information will be entered into the data-table. But they will be sent an email with a link to the requested document. This link shouldn’t be a direct path to the document and we want it to be just a onetime link – argh!!! And that is it!?!!

With what am I having problems:

1. How to check the domain name of the email address.
a. I would assume to use some sort of javascript to check against the data-table that would hold the blocked domain names.
2. Once the domain check has been performed, then posting the email address to the data-table. Then generating an email with a link to the document.

Thanks Again.

buntine
02-24-2004, 11:16 AM
This is far from a simple ASP application, so rather than posting 100's of lines i will just see if i canhelp you with each of your problems.

1. Ok, to check the domain name of the email address we have to first split the email into two smaller strings and then check the second string against a list of domain names.


'|Dimension local variables.
dim strEmail, sendEmail
dim arrDomains(3)
dim i

sendEmail = true '|Set default.

'|Fill array with domains. Add to the list if your want more.
arrDomains(0) = "google.com"
arrDomains(1) = "yoursite.com"
arrDomains(2) = "ebay.com"

'|Split the email into sections and grab the 'domain' part.
strEmail = CStr(Split(Request.form("email"), "@")(1))

'|Loop through the domains and try to make a match.
for i = 0 to UBound(arrDomains)
if arrDomains(i) = strEmail then
sendEmail = false
end if
next


Now we have a boolean variable which we can use later to determine whether to send the email or not.

Ok, problem two. We should be able to use the ASP array that i have described in the preceding example. ASP will not communicate with JavaScript because they do not run on the same machine. ASP = server; JavaScript = client.

Final problem. Now we can use the 'sendEmail' variable which was set before to determine whether we should send the user an email.

if sendEmail = true then
'|Execute the email sending code.

'| Your message body would look something like this:

msgBody = "You can view the file your have requesting by clicking the following link:<br /><br /><a href=""http://www.yoursite.com/docs/" & varWhichHoldsFileName & """>Your File</a><br /><br />From:<br />Your name here.."

else

'|Whatever you wanted the alternative to sending an email.

end if


Phew..
Hope this help you out;)

Regards,
Andrew Buntine.

PeOfEo
02-24-2004, 04:50 PM
Originally posted by buntine
JavaScript because they do not run on the same machine. ASP = server; JavaScript = client. But asp can be done with a few different language, asp is most commonly done using vbscript, but can't it also be written with java script? I know asp.net can be dont with javascript, c#, so on and so fourth.

buntine
02-24-2004, 07:17 PM
Yes, javaScript cant be used. But the MS equivelent JScript is what you may have seen.
There is no need for it here though.

Your can pretty much use any language with ASP.

PeOfEo
02-24-2004, 07:46 PM
Originally posted by buntine
Yes, javaScript cant be used. But the MS equivelent JScript is what you may have seen.
There is no need for it here though.

Your can pretty much use any language with ASP. I thought you were hearded to only 2 or 3 languages though. ASP.NET is amazing though, I mean vb.net c# j# c++.net jscript python (I believe), no matter what programming programming language you are used to useing you can use it with asp.net.

buntine
02-24-2004, 08:05 PM
The same applies for ASP. Just about every language can be used. Even C, C++.
VBScript is the standard because its a MS technology.

Regards.