Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > ASP mailing script not sending mail

Reply
Thread Tools Display Modes

ASP mailing script not sending mail

 
 
SteveH
Guest
Posts: n/a

 
      10-22-2008
Hello

I have the following script which notfies the Webmaster when a user logs on.

I have contacted my hosting service which has provided details of SMTP_USER
and SMTP_PASS and the SMTP_PORT details.

The log-on script users a txt file with the following log-on details: user
name: gates; user's password: bill. Using this user name and password I am
suvccessfully redirected to a 'successful log-on' page.

The problem I am having is that no mail is actually sent to ADMIN_EMAIL.

Are there any obvious errors in the script, please, as I do not get any
server error messages.

Many thanks.

Steve

' Please indicate where notifications should be sent
Const ADMIN_EMAIL = ""

' Please provide the following details for your SMTP server
Const SMTP_SERVER="mail.myServer.com"
Const SMTP_PORT = 25

' If your SMTP server requires authentication, please set
' USE_AUTHENTICATION to True and supply a username and password
Const USE_AUTHENTICATION = True
Const SMTP_USER=""
Const SMTP_PASS="bill"

' If your SMTP server uses Secure Password Aunthentication, please
' set the following value to True.
Const SMTP_SSL = False

' Set this value to true while testing
Const ENABLE_DEBUGGING = False

' Do not change anything below this line
Set WshNetwork = CreateObject("WScript.Network")

dteTime = Time
dteDate = Date

strMessage = "A user has logged onto <b>" & ComputerName & "</b> from <b>" &
WAN_IP & "</b> with the following details:<br><br>" _
& "Logon Date: " & dteDate & "<br>" _
& "Logon Time: " & dteTime & "<br>" _
& "Account Name: " & AccountName & "<br>" _
& "LAN IP: " & LAN_IP & "<br>"

result = SendMail(strMessage)

If ENABLE_DEBUGGING Then WScript.Echo result
WScript.Quit

Function AccountName
If IsNull(WshNetwork) Then Set WshNetwork = CreateObject("WScript.Network")
AccountName = WshNetwork.UserName

End Function

Function ComputerName
If IsNull(WshNetwork) Then Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName

End Function

Function LAN_IP
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select IPAddress from
Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE",,48)

For Each objItem In colItems
If Not IsNull(objItem.IPAddress) Then
LAN_IP = objItem.IPAddress(0)
Exit For
End If
Next

End Function

Function WAN_IP
Set objxmlHTTP = CreateObject("Microsoft.XMLHTTP")
Call objxmlHTTP.open("get", "http://checkip.dyndns.org", False)
objxmlHTTP.Send()

strHTMLText = objxmlHTTP.ResponseText
Set objxmlHTTP = Nothing

If strHTMLText <> "" Then
varStart = InStr(1, strHTMLText, "Current IP Address:", vbTextCompare) + 19
If varStart Then varStop = InStr(varStart, strHTMLText, "</body>",
vbTextCompare)
If varStart And varStop Then strIP = Mid(strHTMLText, varStart, varStop -
varStart)

Else
strIP = "Unavailable"

End If
WAN_IP = Trim(strIP)

End Function

Function SendMail(strBody)
Set objEmail = CreateObject("CDO.Message")
With objEmail
.From = ADMIN_EMAIL
.To = ADMIN_EMAIL
.Subject = "Logon Notification"
.HTMLBody = strBody
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTP_SERVER
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =
SMTP_PORT
If USE_AUTHENTICATION Then
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") =
SMTP_USER
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") =
SMTP_PASS

End If
If SMTP_SSL Then
.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

End If
.Configuration.Fields.Update

On Error Resume Next
Err.Clear

.Send

If Err.number <> 0 Then
SendMail = Err.Description

Else
SendMail = "The server did not return any errors."

End If
On Error Goto 0

End With

End Function
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Error when sending group mailing Gary VanderMolen Windows Vista Mail 2 09-24-2009 09:21 PM
Re: Error when sending group mailing t-4-2 Windows Vista Mail 0 09-24-2009 11:47 AM
bcc: e-mail mailing SJV Windows Vista Mail 3 10-11-2007 08:48 PM
Internet Explorer Script error when sending/receiving mail in Out tamba1 Internet Explorer 1 04-19-2007 07:57 PM
Sending e-mail through script kzawada Scripting 0 08-19-2003 08:45 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59