Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - Logon Script to Send Email Notifications
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Logon Script to Send Email Notifications
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-01-29

    Table of Contents:
  • Logon Script to Send Email Notifications
  • Gathering logon details
  • Creating and sending the notification email
  • Putting it all together

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Logon Script to Send Email Notifications - Putting it all together


    (Page 4 of 4 )

    With all of the pieces in place, it’s time to put this all together.  We need to start by setting the necessary variables for the SendMail function.  These should be configured properly before this script is deployed.

    ' Please indicate where notifications should be sent

    Const ADMIN_EMAIL = "recipient@mail.com"

     

    ' Please provide the following details for your SMTP server

    Const SMTP_SERVER = "smtp.mail.com"

    Const SMTP_PORT = 25 ' Do not change if you are unsure

     

    ' If your SMTP server requires authentication, please set

    ' USE_AUTHENTICATION to True and supply a username and password

    Const USE_AUTHENTICATION = False

    Const SMTP_USER = "username"

    Const SMTP_PASS = "password"

     

    ' If your SMTP server uses Secure Password Authentication, please

    ' set the following value to True.

    Const SMTP_SSL = False

    This code should be at the beginning of your script.  Set any of the necessary constants to ensure that your email will be sent properly.  If you don’t have access to an SMTP server, there are free mail sending services available on the Internet.

    Now it’s time to gather our last bit of details and put our email message together.

    dteTime = Time

    dteDate = Date

    Now is a good time to grab the local date and time stamps.  This can be helpful for tracking logons at a later 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>"

    Here we’re simply assembling a text string containing a simple email message with all of the logon details that have been provided by our functions.

    result = SendMail(strMessage)

    Now we take our message body and pass it to the SendMail function.  This one line does the dirty work.

    That’s the concept in a nutshell.  All that’s left is to set this as a logon script on each of your machines.  In a networked environment, this can usually be done from the server.

    You can download the full source code for this article below to see the complete script in its entirety.  I’ve also added a little bonus that allows you to debug the script before putting it into general use.

    Thanks for reading.  Have some fun with this script.  Until next time, keep coding!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    WINDOWS SCRIPTING ARTICLES

    - Screen Capturing via GDI+ and GDI
    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway