Monday, July 4, 2011

Function to create zip file of folder

Function ZipAttachment

    ZipAttachment = ""

    ' Declare the required variables
    Dim objZip, objSA, objFolder, zipFile, FolderToZip
   
    zipFile = Environment.Value("c:\ResultFolder") & ".zip"
    FolderToZip = Environment.Value("c:\ResultFolder")

    'Create the basis of a zip file.
    CreateObject("Scripting.FileSystemObject") _
    .CreateTextFile(zipFile, True) _
    .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

    ' Create the object of the Shell
    Set objSA = CreateObject("Shell.Application")
   
    ' Add the folder to the Zip
    Set objZip = objSA.NameSpace(zipFile)
    Set objFolder = objSA.NameSpace(FolderToZip)
    objZip.CopyHere(objFolder.Items)
   
    ' Wait for the folder to be added in the zip
    ' Increase the Wait time is the folder is too large
    WScript.Sleep 2000

    ZipAttachment = zipFile

End function

Function to Send mail through vbscript

Function SendMail

    ' Declare the required variables
    Dim strTextBody, MailNotification
    dim strModuleName, intTotalPassed,  intTotalFailed,  intTotalNotExecuted

    ' Assign value to result.
    strModuleName = "Smoke"
    intTotalPassed = 10
    intTotalFailed = 1
    intTotalNotExecuted = 0
   
    ' Prepare the body text
    strTextBody = "==================================" & vbcrlf
    strTextBody= strTextBody & "Test Execution Report" & vbcrlf
    strTextBody= strTextBody & "Date :"  & Date & " " & Time & vbcrlf
    strTextBody= strTextBody & "==================================" & vbcrlf
    strTextBody= strTextBody & "Summary" & vbcrlf
    strTextBody= strTextBody & "==================================" & vbcrlf
    strTextBody= strTextBody & "Total Tests Passed       : " & intTotalPassed & vbcrlf
    strTextBody= strTextBody & "Total Tests Failed       : " & intTotalFailed & vbcrlf
    strTextBody= strTextBody & "Total Tests Not Executed : " & intTotalNotExecuted & vbcrlf
    strTextBody= strTextBody & "==================================" & vbcrlf
    strTextBody = strTextBody  &  "The attachment contains the" & vbcrlf & "results for the following modules:" & vbcrlf
    strTextBody= strTextBody & "==================================" & vbcrlf
    strTextBody= strTextBody & strModuleName   
    strTextBody= strTextBody & "=================================="
   
    ' Create the Mail object
    Set MailNotification=CreateObject("CDO.Message")
   
    ' Set the subject
    MailNotification.Subject = Environment.Value("Smoke result")
   
    ' Set the Mail From parameter
    MailNotification.From = Environment.Value("Manual Team")
   
    ' Set the Mail To parameter
    MailNotification.To = Environment.Value("Manager")
   
    ' Set the Mail CC parameter
    MailNotification.CC = Environment.Value("Test Lead")
   
    ' Set the mail BCC parameter
    MailNotification.BCC= ""
   
    ' Set the Bod of the Mail
    MailNotification.TextBody= strTextBody & vbcrlf & vbcrlf & "DO NOT REPLY. This is an auto-generated mail." & vbcrlf & "Contact the administrator in case of any queries"
   
    ' Add the Attachements  (Zip Attachment is global which contain required result in detail)
    MailNotification.AddAttachment  ZipAttachment

    ' Configure the mail according the smtp server settings
    MailNotification.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
    MailNotification.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Environment.Value("SMTP server")
    MailNotification.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    MailNotification.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0 'cdoBasic
    MailNotification.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 120

    ' Update and send the mail
    MailNotification.Configuration.Fields.Update
    MailNotification.Send
   
    ' Clear the memory
    Set MailNotification=nothing

    Call DNALogEvent("Mail notification sent.")
   
End Function
 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons