Script to send email when error happens (338 Views)
Reply
Frequent Advisor
Jeffery_QA
Posts: 54
Registered: ‎09-16-2013
Message 1 of 3 (338 Views)

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?

 

 

Frequent Advisor
Jeffery_QA
Posts: 54
Registered: ‎09-16-2013
Message 2 of 3 (280 Views)

Re: Script to send email when error happens

Any idea?
HP Expert
Ana_Noncheva
Posts: 245
Registered: ‎08-06-2013
Message 3 of 3 (256 Views)

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.”
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.