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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Automatic

Status
Not open for further replies.

stevemarsh99

Technical User
Aug 10, 2005
88
GB
Hey guys,

I have a page that grabs a date from a database and throws it on a page. fine. but how would i (i lamens terms!) have an email sent out to someone when then outputted date is within 2 days or 1 day, doesnt matter, automatically?

Can this be done?

Ta
Steve
 
Deends on the language you are using

[Peace][Pipe]
 
ASP. Man you are so helpful, thank you for your time my friend...now gimme some help!! :)
 
Suggest you start by reading faq222-2244, especially paragraphs 1 & 2. Then read the rest of the faq, and recompose your question so we can make some sense of it.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Look into CDONTS and just use an if statement to decide the date criterea

[Peace][Pipe]
 
I wish to have a email sent to a person 24 before a date that resides in a database.
 
Then you will need to look at stored procedures in the database, as there may be no guarantee that someone will visit a page that would trigger an email

Cheech

[Peace][Pipe]
 
I mean I would like to have a hard coded date on a page and then an email sent to an address, 1 day before the hard coded date.
I have reasearched into CDONTS and I have a email form working but how would I use this to automatically email someone dependant on the date?

Here is my code for the email form:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/ealert.asp" -->
<%
Dim rs_ealert
Dim rs_ealert_numRows

Set rs_ealert = Server.CreateObject("ADODB.Recordset")
rs_ealert.ActiveConnection = MM_ealert_STRING
rs_ealert.Source = "SELECT * FROM tbl_ealert"
rs_ealert.CursorType = 0
rs_ealert.CursorLocation = 2
rs_ealert.LockType = 1
rs_ealert.Open()

rs_ealert_numRows = 0
%>
<%
if Request.Form("FFSubmitted") = "yes" then
Dim BodyString
Dim objCDO
Dim RedirectURL
Dim FormFields
Dim arrFormFields
FormFields = "to~body~subject"
If FormFields <> "" Then
arrFormFields = split(FormFields,"~")
End If
Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.From = "eAlert@system.com"
objCDO.To = "anyone@hotmail.com"
objCDO.Cc = ""
objCDO.Bcc = ""
objCDO.Subject = "tester subject line"
BodyString = Replace("Tester body","~",chr(13) & chr(10) )& chr(13)
If FormFields <> "" Then
For Each item In arrFormFields
BodyString = BodyString & item & ": " & Request.Form(item) & chr(13)
Next
End If
objCDO.Body = BodyString
objCDO.BodyFormat = 1
objCDO.MailFormat = 1
objCDO.Send
Set objCDO = Nothing
RedirectURL = ""
If RedirectURL <> "" then
If Request.QueryString <> "" Then
response.redirect(RedirectURL & "?" & Request.QueryString)
else
response.redirect(RedirectURL)
end If
end if
end if
%>
<% MM_EditAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
MM_EditAction = MM_EditAction & "?" & Request.QueryString
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<title>KHL Digital Magazine eAlerts</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
-->
</style>
<link href="css/Main_page.css" rel="stylesheet" type="text/css">
</head>

<body>

<form action="<%=MM_editAction%>" method="post" name="email_form" id="email_form">
<p>
<input name="to" type="text" id="to">
to </p>
<p>
<input name="body" type="text" id="body">
subject </p>
<p> <input name="subject" type="text" id="subject">
body</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<input type="hidden" name="FFSubmitted" value="yes">
</form>
</body>
</html>
<%
rs_ealert.Close()
Set rs_ealert = Nothing
%>
 
A page does not exist until someone visits it. So it cannot automatically send an email depending on the date. That is why I suggest the stored procedures.

If its an admin function that someone does every day then you can just use a date comparrison that processes the form using an if statement. eg

if yourhardcodedDate = dateadd("d", date(), -1) then
CDO code here
else
alt code here
end if

Cheech

[Peace][Pipe]
 
I have looked into SP's and they look good but I dont understand where I get it to link to the date? Would I have the CDO code in a page ready and then get the database to somehow 'run' the page every hour or daily to force the CDO script to run?
 
You would need a scheduler to run on the database to initiate the SP

[Peace][Pipe]
 
The problem I have is i get up to the Stored Procedure in Access but I dont know how to use this in an asp page?

I also dont really understand what the stored procedure will do the job I would like!

 
OK then is this an intranet? Do you have a spare pc anywhere? You could just create page to extract all relevant records from the database and send out the emails (cdo code inside a repeat region). You could then have a javascript counter to run for a set time and then reload the page.

Not the best solution but it would work

Cheech

[Peace][Pipe]
 
Yes its for a intranet. I could have the page load up and constantly run on the web server?

The situation is this:

I have dates that change every month, a user will input them and they get thrown into a database. They are then outputted onto the main page.
On this main page I want to have the cdo code on here to email people 1 day before the date that was previosuly inputted (a reminder if you will).

You think it could work?
 
There are packages that bolt on to Access but they seem to be about $500. The page should work, just set up a cdo page with a reload in it and set the email to your own to test it.

Cheech

[Peace][Pipe]
 
If 29/09/2005 = dateadd("d", date(), 1) then

CDO Code here

Else

Alternate Code here

End If


Doesnt work? I always get the alternate email being sent? Am I right in asaying the adddate function means:

d = day, date() = current date) and 1= variant?

What the heck am I doing wrong?
 
you are adding 1 day to todays date try using -1 instead

[Peace][Pipe]
 
Try using datediff instead
Code:
if (datediff("d", myDate, Date()) = 1) then
cdo code
else
alt code
end if



[Peace][Pipe]
 
Guys the the Date diff does not work, nor does the first one you suggested.

any thoughts?

Thanks
Steve

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top