Wednesday, May 20, 2009

MS Outlook Objcet Model : Send Email with Attachments

Set myOLApp = CreateObject("Outlook.Application")
Set myNameSpace = myOLApp.GetNameSpace("MAPI")
Set olMail = myOLApp.CreateItem(olMailItem)
set WshShell = CreateObject("WScript.Shell")

attachFile = "C:\test.txt"
With olMail
.to =""
.Subject = "Test Mail from QTP with Attachments"
.Body = "This is mail"
.NoAging = True
.Display
End With

Set myAttach = olMail.Attachments
myAttach.Add(ResFile)
'To avoid the display of modal dialog when trying to send email, use shortcut key CTRL S'
WshShell.SendKeys "%{s}"
Set myAttachments = Nothing
Set olMail = Nothing
Set myOLApp = Nothing

No comments: