Click to See Complete Forum and Search --> : Cdosys


RobertSims
06-14-2006, 10:41 AM
I have looked at many of the examples of CDOSYS on here; however, I think I am missing something that I need to understand in order to use it.
The below code works with no problems. The issue I am having is that it executes immediately when the page loads. How do I control *WHEN* the code should execute? I have attempted to put it in a script/function call but it still executes instantly on page load.

Thanks!
--Robert Sims
------------------------------------------------------------------------------------------------
<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows Library" -->
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->

<%
Dim ObjSendMail
Dim iConf
Dim Flds

Set ObjSendMail = Server.CreateObject("CDO.Message")
Set iConf = Server.CreateObject("CDO.Configuration")

Set Flds = iConf.Fields
With Flds
.Item(cdoSendUsingMethod) = 2
.Item(cdoSMTPServer) = "mail"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPconnectiontimeout) = 10
.Update
End With

Set ObjSendMail.Configuration = iConf

Set ObjSendMail.Configuration = iConf
ObjSendMail.To = "you@there.com"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = "me@here.com"

' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "this is the body"

ObjSendMail.Send

Set ObjSendMail = Nothing
Set iConf = Nothing
Set Flds = Nothing
%>
------------------------------------------------------------------------------------------------

russell
06-14-2006, 12:07 PM
This will work. comment the call to SendMAil at the top and the email won't be sent. Ideally there would be a condition that would cause the method to be called... If that condition is the submit of a form, reloading the page (thus, resubmitting the form) would cause it to e sent every time you reload.

<%
Response.ExoiresAbsolute = Date()-1

SendMail

Sub SendMail()
Dim ObjSendMail
Dim iConf
Dim Flds

Set ObjSendMail = Server.CreateObject("CDO.Message")
Set iConf = Server.CreateObject("CDO.Configuration")

Set Flds = iConf.Fields
With Flds
.Item(cdoSendUsingMethod) = 2
.Item(cdoSMTPServer) = "mail"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPconnectiontimeout) = 10
.Update
End With

Set ObjSendMail.Configuration = iConf

Set ObjSendMail.Configuration = iConf
ObjSendMail.To = "you@there.com"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = "me@here.com"

' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "this is the body"

ObjSendMail.Send

Set ObjSendMail = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Sub
%>

RobertSims
06-14-2006, 03:38 PM
Would that code be used in the <body> section? Also, how would I call the sub via a button?

russell
06-14-2006, 04:40 PM
no, see below

<%
Response.ExoiresAbsolute = Date()-1

If Len(Request.Form("mailIt")) Then
SendMail
End If

Sub SendMail()
Dim ObjSendMail
Dim iConf
Dim Flds

Set ObjSendMail = Server.CreateObject("CDO.Message")
Set iConf = Server.CreateObject("CDO.Configuration")

Set Flds = iConf.Fields
With Flds
.Item(cdoSendUsingMethod) = 2
.Item(cdoSMTPServer) = "mail"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPconnectiontimeout) = 10
.Update
End With

Set ObjSendMail.Configuration = iConf

Set ObjSendMail.Configuration = iConf
ObjSendMail.To = "you@there.com"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = "me@here.com"

' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "this is the body"

ObjSendMail.Send

Set ObjSendMail = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Sub
%>
<html>
....
<form method=post action="thisFile.asp">
<input type=hidden name=mailIt value="1">
<input type=submit value="Click To Send Mail">
</form>
...
</html>

RobertSims
06-14-2006, 05:00 PM
I see... thanks for clearing that up! Makes a lot more sense to me now!