Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding attachment to Outlook Email
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
i have code that creats and send an email after my testing completes. But I cannot seem to get the attachment to attach in Outlook v2007 pro.

My code is such:

Code:
'Returns O:\QTP Tests\NightlyRegressionTesting\Tests\Image Access - Check Fax Status by ENV\Res##
msgbox strAttachment

strAttachment = strAttachment & "\Report\Results.xml"
'Returns O:\QTP Tests\NightlyRegressionTesting\Tests\Image Access - Check Fax Status by ENV\Res##\Report\Results.xml
msgbox strAttachment

'all three FAIL
newMail.AddAttachments(strAttachment)
newMail.Attachments.Add(strAttachment)
newMail.Attachments(strAttachment)
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
Try this :-

Code:
newMail.Attachments.Add (strAttachment)
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
Thx Ssvali

I tried newMail.Attachments.Add (strAttachment) earlier but I get a Run Error "The Operation failed...."

I also tried just newMail.Attachments (strAttachment) which does not fail but no attachment is ever added.

I did look over that the strAttachment is correctly found my file by testing If strAttachment <> "" Then, which passes. but, no file gets attached as thought.

thx for your time.


Reply
#4
Solved: 11 Years, 3 Months, 4 Weeks ago
For me the below script is working fine.

Code:
Set olapp = CreateObject("Outlook.Application")
Set olns = olapp.GetNameSpace("MAPI")
Set msg = olapp.CreateItem(mailitem)
Set rep = msg.Recipients.Add ("abc@qtp.com")

msg.subject = "Test Mail"
msg.body = "Mail from QTP"
fattach = "Z:\Results\Result.xml"
msg.Attachments.Add (fattach)
msg.send
Reply
#5
Solved: 11 Years, 3 Months, 4 Weeks ago
Mine still fails at: msg.Attachments.Add (fattach)

I tried:
Code:
Set olapp = CreateObject("Outlook.Application")
Set olns = olapp.GetNameSpace("MAPI")
Set msg = olapp.CreateItem(mailitem)
Set rep = msg.Recipients.Add ("abc@qtp.com")

msg.subject = "Test Mail"
msg.body = "Mail from QTP"
fattach = "C:\Document and Settings\Desktop\Result.xml"
msg.Attachments.Add (fattach)
msg.send

I do ret a Run Error: Cannot find this file. (but it is there)

Thx for the idea
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Send automatic email notification when test run started helmzshelmz 0 1,079 04-03-2020, 07:54 AM
Last Post: helmzshelmz
  Pages and Frames adding _1, _2, _3... zunebuggy 1 1,671 05-30-2017, 12:17 AM
Last Post: Vichu M J
  Adding negative amount in webedit Rose 1 2,142 06-30-2016, 09:34 PM
Last Post: babu123
  Adding data into rows that add dynamically with setcelldata azar81 4 5,936 04-13-2015, 05:24 PM
Last Post: vidya2k2
  How to attach HTML file to Email Naresh 0 3,069 04-06-2015, 02:04 PM
Last Post: Naresh

Forum Jump:


Users browsing this thread: 2 Guest(s)