How do you send email with attachment from outlook using qtp ?

Questions by Richi   answers by Richi

Showing Answers 1 - 9 of 9 Answers

Ur Friend

  • Nov 20th, 2007
 

Function AttachHTMLAsMailContent(sSendTo, sSendToCC,sSendToBCC,sSubject,sHtmlPath)

Dim objOutlook
Dim objOutlookMsg
Dim olMailItem

' Create the Outlook object and the new mail object.
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

' Define mail recipients
objOutlookMsg.To = sSendTo
objOutlookMsg.CC = sSendToCC
objOutlookMsg.BCC = sSendToBCC

' Body of the message

With objOutlookMsg
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(sHtmlPath,1)
strText = ts.ReadAll
.HTMLBody = strText
.Display
End With

' Send the message
objOutlookMsg.Send
wait(3)

' Release the objects
set objOutlook = nothing
set objOutlookMsg = nothing

End Function


'Sample usage
'AttachHTMLAsMailContent "MyName@abc.com","","","TestResults-MultipleAttachments","D:TestCase.html"


  Was this answer useful?  Yes

Try the below code. It will send an email with attachment.

Public Function Send_Mail(Module)
  strSubject="Test mail - Sent from QTP"
  Set objOutlook=CreateObject("Outlook.Application")
  Set objMail=objOutlook.CreateItem(0)
  objMail.to= "mailto@xyz.com"
  objMail.CC="mailcc@xyz.com"
  objMail.Bcc="mailbcc@xyz.com"
  objMail.Subject=strSubject
  objMail.Body= "This is a test email sent from QTP " & chr(13) & " " & "Regards," & chr(13) & "Testing team"
   objMail.Attachments.Add(attachFile) 'attachFile is a variable which helds the file name with its complete path
  wait(2)
  objMail.Display     'Displays e-mail message window
  wait(2)
  objMail.Send
  Wait (30)
  objOutlook.Quit

  Set objMail = Nothing
  Set objOutlook = Nothing
End Function

Anish10110

  • Nov 19th, 2011
 

To add multiple attachments in a single mail, repeat objMail.Attachments.Add line multiple number of times.


Example: If you need to add 2 attachments in your email use the above line 2 times.

objMail.Attachments.Add("D:Sample_Attachment_1.txt")
objMail.Attachments.Add("D:Sample_Attachment_2.txt")

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions