Unified Functional Testing Practitioners Forum
Showing results for 
Search instead for 
Do you mean 

Script to send email when error happens

Frequent Advisor

Script to send email when error happens

Purpose: send an email when error happens and when test running end.

 

Here is the script:

 

Set ol=CreateObject("Outlook.Application")
SendTo="********"
SendToCC="***********"
Subject="Test Status of "&Environment.Value("TestName")

Select case Reporter.RunStatus
Case "1" Body="Fail"
Case "2" Body="Done"
Case "3" Body="Warning"
Case "0" Body="Pass"
Case Else Body="Unexpected result"
End Select
attachment=""
'Create a new outlook mail object
Set Mail=ol.CreateItem(0)

'Add the email address to the recipient list of the message
Mail.to=SendTo
Mail.CC=SendToCC
'Add the subject of the message
Mail.Subject=Subject

'Add the body of the mail message
Mail.Body=Body

'Add the attachment to the mail message
If (Attachment <> "") Then
Mail.Attachments.Add(Attachment)
End If

'Send the mail message
Mail.Send

ol.Quit
Set Mail = Nothing
Set ol = Nothing

 

Issue: emails are stuck in outbox of outlook. 

 

Any solution for this?

 

 

2 REPLIES
Frequent Advisor

Re: Script to send email when error happens

Any idea?
HPE Expert

Re: Script to send email when error happens

Hello,

 

This is VBScript issue independent of QTP/UFT and therefore out of scope of this forum and HP Support.

 

However, I tested your script and think that the problem is with quiting Outlook before sending the mail is complete.

(You can check this by commenting out ol.Quit > Is item sent correctly in this case?)

Maybe you should check your Outbox first for any left items before proceeding with ol.Quit.

Check Outlook Object model for available objects with methinds and properties to use for this: http://msdn.microsoft.com/en-us/library/office/ff866465.aspx

 

Hope this helps.

 

Regards,

Ana

“HP Support
If you find that this or any post resolves your issue, please be sure to mark it as an accepted solution.”