This topic is locked
[SOLVED]

 EMail code question

5/4/2011 9:59:36 AM
ASPRunnerPro General questions
B
beachldy author

This code gets no syntax errors, but is not working. It runs on "after record is added", but this code seems to lock up the form and the record is not saved. No error messages.
** Send email with new data ****

' do not forget to setup email parameters like From, SMTP server etc

' on 'Security->User login settings' dialog
if values("Status")= "Scheduled" then
Dim tmpDict, msg, msg2

msg ="You have entered a new " & values("status") & " entry for " & values("CustID") & vbcrlf
set tmpDict = CreateObject("Scripting.Dictionary")

tmpDict("to")=values("DriverEmail") ' tmpDict("to")=Dict("DriverEmail")

tmpDict("subject")="NEW SCHEDULE"

tmpDict("body")=msg

set ret=runner_mail(tmpDict)

if not ret("mailed") then

response.write ret("message")

end if
End If

Sergey Kornilov admin 5/4/2011

Code that is added to AfterAdd event won't affect save record functionality. If record is not saved you must be dealing with something else.
I would suggest to remove this code for test purposes to see what happens.

B
beachldy author 5/6/2011

Actually I got email to work using a Google account!
If values("Status")<> "Pending" then
'**

Const fromEmail = "whoever@gmail.com"

Const password = "mypwd"

'**

Dim CustIDCur, rs, CustName, msg, DriverEmail, Stat, DriverIDCur,DriverName

CustIDCur = values("CustID")

DriverIDCur = values("DriverID")

If values("Status") = "Scheduled" then

Stat = "NEW SCHEDULE HAS BEEN ADDED: "

ELseif values("Status") = "Cancelled" then

Stat = "SCHEDULE HAS BEEN CANCELLED :"

End If

DriverEmail = values("DriverEmail")
set rst = dal.Table("tblCustomers").Query("CustID=" & CustIDCur ,"")

CustName = rst("Fname") & " " & rst("LName")

rst.Close:set rst = Nothing
set rst = dal.Table("tblDrivers").Query("DriverID=" & DriverIDCur ,"")

DriverName = rst("DriverFname") & " " & rst("DriverLName")

rst.Close:set rst = Nothing
msg = Stat & " " & DateValue(values("StartDate")) & " " & Timevalue(values("StartTime")) & vbcrlf

msg = msg & " for Customer: " & CustName & vbcrlf

msg = msg & " for Driver: " & DriverName
Dim emailObj, emailConfig

Set emailObj = CreateObject("CDO.Message")

emailObj.From = "SCHEDULING WEBSITE"

emailObj.To = DriverEmail

emailObj.Subject = "Schedule Change"

emailObj.TextBody = msg
'If WScript.Arguments.Count > 3 Then

'emailObj.AddAttachment WScript.Arguments.Item(3)

'End If
Set emailConfig = emailObj.Configuration

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver";) = "smtp.gmail.com"

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport";) = 465

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing";) = 2

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate";) = 1

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl";) = true

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername";) = fromEmail

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword";) = password

emailConfig.Fields.Update
emailObj.Send
Set emailobj = nothing

Set emailConfig = nothing
End If