| || |
Validating that email has been sent?
I'm currently evaluating Robot and QTP and am very new to testing in general, so please bear with me.
Re: Validating that email has been sent?
'This is actually VB Code
'You can use it in VBScript also
'The follwing variable declarion is disabled as
'you can declare variables in this way in VBS
'Dim objSess As MAPI.Session
'Dim objMsg As Message
'Dim objSentMsg As Message
'Dim objMyField As Field
'Dim objMessColl As Messages
'Dim objMsgFilter As MessageFilter
'Dim objInfoStores As InfoStores
'Dim objRootFolder As Folder
'Dim objFolders As Folders
'Dim objSentItems As Folder
'Dim objOutbox as Folder
Set objSess = CreateObject("mapi.session")
objSess.Logon "sai" 'Put a valid profile name here.
Set objOutbox = objSess.Outbox
Set objMsg = objOutbox.Messages.Add
'Add some default data to your message before showing it to the user.
.Text = "This is my text."
.Subject = "This is my subject."
.Recipients.Add "email@example.com" 'Put a valid
'recipient name here.
' Add a dummy field with unique content to the message object
' to identify the message, later on. If guaranteed uniqueness is
' important a GUID would be more appropriate but for simplicity we
' will use the current "system date and time" for the content of the
Mytime = Now
Set objMyfield = objMsg.Fields.Add("MyField", 8)
objMyfield.Value = Mytime
myfieldID = objMyfield.ID
' Save the changes you made to the message.
' Display the message window.
' Get the "Sent Items" Folder
' Note: If you use CDO 1.2 or CDO 1.21 library, you can get the "Sent
' Items" folder by simply calling GetDefaultFolder method of the
' Session object as follows. If this is the case, uncomment the
' following line of code and comment out the lines in between ' *\*
' and ' */*
'Set objSentItems = objSess.GetDefaultFolder(3)
Set objInfostore = objSess.InfoStores
CountInfoStores = objInfostore.Count
FoundMailbox = False
For i = 1 To CountInfoStores
If Mid(objInfostore(i), 1, 7) = "Mailbox" Then
FoundMailbox = True
Set objRootFolder = objInfostore(i).RootFolder
Set objFolders = objRootFolder.Folders
For j = 1 To objfolders.Count
If objFolders(j).Name = "Sent Items" Then
Set objSentItems = objFolders(j)
If FoundMailbox = True Then
Set objMessColl = objSentItems.Messages
Set objMsgFilter = objMessColl.Filter
' Setup a filter that passes only messages with the dummy field .
objMsgFilter.Fields(myfieldID) = Mytime
For Each objSentMsg In objMessColl
Set objSentMsg = Nothing
Set objMyField = Nothing
Set objMessColl = Nothing
Set objMsgFilter = Nothing
Set objSentItems = Nothing
Set objOutbox = Nothing
' Comment out the following lines if you used the GetDefaultFolder
Set objInfoStore = Nothing
Set objRootFolder = Nothing
Set objFolders = Nothing
Set objSess = Nothing