'MicroSoft Office Basic Operations
Function funcOutlookBasicOperations()
'Create MicroSoft Outlook Object
Set objMSOutLook = CreateObject("Outlook.Application")
'GetNameSpace for MAPI
Set objOutLookNameSpace = objMSOutLook.GetNamespace("MAPI")
'Get Number of Folders
intFoulderCount = objOutLookNameSpace.Folders.Count
MsgBox "Number of Folders Available: "& intFoulderCount
'Displaying the Folders
For i = 1 intFoulderCount
intFoulderName = objOutLookNameSpace.Folders.Item(i)
MsgBox "Folder Name: "& intFoulderName
Next
'Outlook Version
strOutLookVersion = objMSOutLook.Version
MsgBox "OutLook Vesion: "& strOutLookVersion
'Logged In UserName
strUserName = objOutLookNameSpace.CurrentUser
MsgBox "Logged In UserName: "& strUserName
'Quit OutLook
objMSOutLook.Quit
Set objOutLookNameSpace = Nothing
Set objMSOutLook = Nothing
End Function
'Open Outlook with QTP
Function funcOpenOutlookWithQTP()
'Verify MicroSoft OutLook Already Open
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objTaskManagerProcess = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'OutLook.exe'")
If objTaskManagerProcess.Count <> 0 Then
MsgBox "MicroSoft OutLook Application Already Open"
Else
'Create MicroSoft Outlook Object
Set objMSOutLook = CreateObject("Outlook.Application")
'GetNameSpace for MAPI
Set objOutLookNameSpace = objMSOutLook.GetNamespace("MAPI")
'Displaying Default Folder - Inbox
Set objInboxFolder = objOutLookNameSpace.GetDefaultFolder(6)
objInboxFolder.Display
'Quit OutLook
objMSOutLook.Quit
Set objTaskManagerProcess = Nothing
Set objInboxFolder = Nothing
Set objMSOutLook = Nothing
End If
End Function
'Display All Subfolder from Inbox Folder
Function funcDisplayAllInboxSubFolders()
'Create MicroSoft Outlook Object
Set objMSOutLook = CreateObject("Outlook.Application")
'GetNameSpace for MAPI
Set objOutLookNameSpace = objMSOutLook.GetNamespace("MAPI")
'Displaying Default Folder - Inbox
Set objInboxFolder = objOutLookNameSpace.GetDefaultFolder(6)
'Get Subfolder Count
intInboxSubFolderCount = objInboxFolder.Folders.Count
MsgBox "Total Number of Sub Folders from Inbox: "& intInboxSubFolderCount
'Displaying Sub Folders
Set arrSubFolders = objInboxFolder.Folders
For i = 1 to intInboxSubFolderCount
MsgBox "Sub Folder Name: " & arrSubFolders(i)
Next
'Quit OutLook
objMSOutLook.Quit
Set objOutLookNameSpace = Nothing
Set objInboxFolder = Nothing
Set arrSubFolders = Nothing
Set objMSOutLook = Nothing
End Function
'Add and Remove Folder to Inbox Default Folder
Function funcAddAndRemoveToInbox()
'Create MicroSoft Outlook Object
Set objMSOutLook = CreateObject("Outlook.Application")
'GetNameSpace for MAPI
Set objOutLookNameSpace = objMSOutLook.GetNamespace("MAPI")
'Displaying Default Folder - Inbox
Set objInboxFolder = objOutLookNameSpace.GetDefaultFolder(6)
'Add Folder
objInboxFolder.Folders.Add "TestingConnect"
'Deleting the Folder
'Get Subfolder Count
intInboxSubFolderCount = objInboxFolder.Folders.Count
MsgBox "Total Number of Sub Folders from Inbox: "& intInboxSubFolderCount
'Displaying Sub Folders
Set arrSubFolders = objInboxFolder.Folders
For i = 1 to intInboxSubFolderCount
MsgBox "Sub Folder Name: " & arrSubFolders(i)
'Deleting the Folder
If arrSubFolders(i).Name = "TestingConnect" Then
arrSubFolders(i).Delete
End If
Next
'Quit OutLook
objMSOutLook.Quit
Set objOutLookNameSpace = Nothing
Set objInboxFolder = Nothing
Set arrSubFolders = Nothing
Set objMSOutLook = Nothing
End Function
'Send an EMail Using OutLook Object in QTP
Function funcSendAnEMailFromYourOutLook()
'Create MicroSoft Outlook Object
Set objMSOutLook = CreateObject("Outlook.Application")
'GetNameSpace for MAPI
Set objOutLookNameSpace = objMSOutLook.GetNamespace("MAPI")
'Displaying Default Folder - Inbox
Set objInboxFolder = objOutLookNameSpace.GetDefaultFolder(6)
objInboxFolder.Display
'Open New Mail
Set objEMail = objMSOutLook.CreateItem(0)
'Setting up Different Fields for Your EMail to be Send
objEMail.To = "SoftwareTesting.Connect@gmail.com"
objEMail.CC = "SoftwareTesting.Connect@gmail.com"
objEMail.BCC = "SoftwareTesting.Connect@gmail.com"
objEMail.Subject = "Sending an EMail using Outlook Object in QTP"
objEMail.Body = "Sending an EMail using Outlook Object in QTP"
objEMail.Attachments.Add("C:\Sample.txt")
'Send Email
objEMail.Send
Wait 20
'Quit OutLook
objMSOutLook.Quit
Set objEMail = Nothing
Set objMSOutLook = Nothing
End Function
'Send an EMail Using GMail Object in QTP
Function funcSendAnEMailFromGmail()
'Create MicroSoft Outlook Object
Set objGMail = CreateObject("CDO.Message")
'Enable SSL Authentication
objGMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
'Enable basic smtp authentication
objGMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Specify SMTP server and port
objGMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.gmail.com"
objGMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objGMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Specify user id and password
objGMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "balaraju.s@gmail.com"
objGMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "sdfasd"
'Update the configuration fields
objGMail.Configuration.Fields.Update
'Setting up Different Fields for Your EMail to be Send
objGMail.To = "bala.sangaraju@gmail.com"
objGMail.From = "balaraju.s@gmail.com"
objGMail.CC = "SoftwareTesting.Connect@gmail.com"
objGMail.BCC = "SoftwareTesting.Connect@gmail.com"
objGMail.Subject = "Sending an EMail using Outlook Object in QTP"
objGMail.TextBody = "Sending an EMail using Outlook Object in QTP"
objGMail.AddAttachment "C:\Sample.txt"
'Send Email
objGMail.Send
Wait 20
Set objGMail = Nothing
End Function
'Send an EMail Using YahooMail Object in QTP
Function funcSendAnEMailFromYahooMail()
'Create MicroSoft Outlook Object
Set objYahooMail = CreateObject("CDO.Message")
'Enable SSL Authentication
objYahooMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
'Enable basic smtp authentication
objYahooMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Specify SMTP server and port
objYahooMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.mail.yahoo.com"
objYahooMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objYahooMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Specify user id and password
objYahooMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "balaraju.s@Yahoo.com"
objYahooMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "sdfasd"
'Update the configuration fields
objYahooMail.Configuration.Fields.Update
'Setting up Different Fields for Your EMail to be Send
objYahooMail.To = "bala.sangaraju@Yahoo.com"
objYahooMail.From = "balaraju.s@Yahoo.com"
objYahooMail.CC = "SoftwareTesting.Connect@gmail.com"
objYahooMail.BCC = "SoftwareTesting.Connect@gmail.com"
objYahooMail.Subject = "Sending an EMail using Outlook Object in QTP"
objYahooMail.TextBody = "Sending an EMail using Outlook Object in QTP"
objYahooMail.AddAttachment "C:\Sample.txt"
'Send Email
objYahooMail.Send
Wait 20
Set objYahooMail = Nothing
End Function
No comments:
Post a Comment