VBScript connect Oracle, send mail by gmail

VBScript connect Oracle, send mail by gmail



Source code:
Dim strSQL
Dim strUsername
Dim strPassword
Dim snpData
Dim dbMyDBConnection
Set snpData = CreateObject("ADODB.Recordset")
Set dbMyDBConnection = CreateObject("ADODB.Connection")
strUsername = "USERNAME"
strPassword = "PASSWORD"
dbMyDBConnection.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=YOURDBSERVER/orcl;User ID=" & strUsername & ";Password=" & strPassword & ";"
dbMyDBConnection.Open
strSQL = "select extract(minute from systimestamp) saitime from DUAL"
snpData.Open strSQL, dbMyDBConnection
If Not(snpData.EOF) Then
If cInt(snpData("saitime")) > cInt(5) Then
dim oMsg
Set oMsg = CreateObject("CDO.Message")
oMsg.From ="sendtochinh@gmail.com"
oMsg.to ="sendtochinh@gmail.com"
oMsg.cc =""
oMsg.Subject = "Mail Title"
oMsg.TextBody = "Mail Body" & vbCrLf & vbCrLf & "Time:" & Now
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "sendtochinh@gmail.com"
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "***"
oMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
oMsg.Configuration.Fields.Update
oMsg.Send
Set oMsg = Nothing
End if
End If
snpData.CLose
Set snpData = Nothing
dbMyDBConnection.Close
Set dbMyDBConnection = Nothing

※Note: Allowing less secure apps to access your gmail account

No comments

Powered by Blogger.