Send email with attachment from outlook using QTP:


Send email with attachment from outlook using QTP:

QTP send result in emailStakeholders are the persons to whom we need to report the coverage of our day to day testing activities.Members of management relies on the data..that’s it! They do not give damn interest on whether your scripts is running or not.I have seen most of my colleagues enjoying after the successful run of their scripts.Well, the mission of automation developer is not simply to run scripts or to debug.Automation developers are still the testers and the mission of automation and manual testers is same.Frequent manual intervention hassles our automation work.It’s wise to find out and reduce the human intervention on the running and ran scripts.After run session it’s wise to bundle up the result dumps, attach in mail and send to one/more of our stakeholders.Outlook provides a simpler way to achieve the same, before running the scripts you must make sure that outlook express has been configured on your machine.If outlook hasn’t been configured on your system then send mail functionality would not work.You could ask your tech-support guys to configure your outlook application to have a smooth ride.

Code:

'**********************************************
'Function: Sendmail_fromQTP
'Arguments:
                   'sMailto:Recipient email address

                   'sSubject:Mail subject

                   'sBody:Mail body text

                   'sAttachment: Attachment file path

'Description:Send mail using Outlook express
'Author:QTP Lab:--A touch of madness
'Website:https://automationlab09.wordpress.com
'Last modified:19/07/2010

'*********************************************

Function Sendmail_fromQTP(sMailto,sSubject,sBody,sAttachment)

set oMailobj=CreateObject("Outlook.Application")

set oSendmail=oMailobj.CreateItem(0)
      oSendmail.To=sMailto
      oSendmail.Subject=sSubject
      oSendmail.Body=sBody
      If (sAttachment <> "") Then
         oSendmail.Attachments.Add(sAttachment)
      Else
           Reporter.ReportEvent micInfo,"Sending mail:","Unable to send attachment,please verify your attachment file"

       End If 

       oSendmail.Send

set oSendmail=Nothing
set oMailobj=Nothing

End Function

'Usage:
 Sendmail_fromQTP "name@example.com","Mail from QTP","Your mail descrn goes here..","C:\test.txt"

I haven’t ran the code,please do let me know if you face any difficulties while working on above script.
Thank you!

Advertisements

5 responses to this post.

  1. Posted by Manish on August 16, 2010 at 4:34 pm

    I am facing issue with attachments, i dont know why, but while sending email with attachment, it is not attaching the file when i m using QTP, but executing this outside QTP, as a vbscript working fine

    Reply

  2. Hello manish!
    What error exactly it’s(QTP) throwing away?

    Reply

  3. Posted by Vishal Jain on November 12, 2010 at 7:40 am

    I am gettig a popup message of outlook where it says that outlook is sending message click yes or no.

    Is there any way to bipass ths popup. I don’t want to bipass this popup by clicking yes using record or through descriptive programming.

    Reply

    • Hi Vishal,call the below function wherever pop up occurs:

      Function ClosePopup()

      Set process = GetObject(“winmgmts:\\”)

      Set allPopups = process.ExecQuery(“Select * from Win32_Process Where Name = ‘wscript.exe'”)

      For Each Popup in allPopups
      Popup.Terminate()
      Next

      End Function

      Reply

      • Posted by Anonymous on November 24, 2010 at 7:42 am

        Its an outlook popup and terminating it will not help. I need to click yes on it in order to send an email

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: