Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sending email through qtp
#1
Solved: 10 Years, 8 Months, 3 Weeks ago
Hi,
I have tried the below piece of code, i was able to send email through qtp, but i didn't wanted to invoke outlook each time, i run, so i added piece of code intially which checks whether the outlook is open.

Code:
Set mailob = GetObject(", outlook.application")
If Not Obj Is Nothing Then
Msgbox "Outlook is already open"
Else
systemUtil.Run "OUTLOOK.EXE"
End If
Set Obj = Nothing
'systemUtil.Run "OUTLOOK.EXE" ' Comment this line, if outlook is already open
Set Wshshell = CreateObject("Wscript.Shell")
set mailob = createobject("outlook.application")
wait(5)
set mailitm = mailob.createitem(0)
wait(5)
mailitm.display 'this being an optional step
wait(5)
mailitm.to = "dtulasi@abc.com"
mailitm.cc = "dtulasi@xyz.com;dtulas@zyx.com"
wait(5)
mailitm.subject = "QTP Result"
wait(5)
mailitm.attachments.add ("C:\Documents and Settings\Administrator\Desktop\Test3\Res1\Report.xml") 'path of file
mailitm.send
I am facing 2 propblems over here

At line 1 iam getting general error

and also i am manually specifying the attachment path, that too isn't working, is there any way that i can change this hard coded path

Any help would be really appreciated.

Regards;
Vijay
Reply
#2
Solved: 10 Years, 8 Months, 3 Weeks ago
use 'CreateObject' instead of 'GetObject', also to check whether it is open or not, you will have to check in the processes (you can use WMI scripting).

Reply
#3
Solved: 10 Years, 8 Months, 3 Weeks ago
Hi,
Thanks for a quick response.
I also have other problem, some thing to do with the path of the file to be attached.


mailitm.attachments.add ("C:\\Documents and Settings\\Administrator\\Desktop\\Test3\\Res1\\Report.xml") .

As the path of the result file varies with the testname, i dont want to hardcord it.

Is there any way that i cannot hard code it.

Any reply would be really appreciated.
Regards;
Vijay
Reply
#4
Solved: 10 Years, 8 Months, 3 Weeks ago
Hi,

You can use Built-In Environment variables in the below way.

Code:
mailitm.attachments.add (Environment("ResultDir")&"Report.xml")
Reply
#5
Solved: 10 Years, 8 Months, 3 Weeks ago
Hi,
Thanks a lot for the quick response.

Regards;
Vijay
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting Email Body from Outlook waseem.khan.91 0 1,877 03-04-2019, 02:53 PM
Last Post: waseem.khan.91
  Extracting Email Body from Outlook waseem.khan.91 0 1,020 03-01-2019, 02:51 PM
Last Post: waseem.khan.91
  Find the email using subject with the help of vb script Raheem Shaik 0 1,447 12-12-2018, 02:57 PM
Last Post: Raheem Shaik
Rolleyes Urgent help with Gmail Sending mail feature nidhitaneja 2 2,729 03-05-2014, 09:39 PM
Last Post: nidhitaneja
  Cannot attach the text file to email arpan 2 3,264 07-19-2013, 12:13 AM
Last Post: arpan

Forum Jump:


Users browsing this thread: 1 Guest(s)