Friday, February 13, 2009

Send Email from Outlook with QTP code

We can send E-Mail with creating Object for Outlook. In below example code we can send mail with CC, BCC recipients and Attachment.

Below is a list of all default folder constants in MS Outlook.


'Folder Constants
olFolder=3 'Deleted items
olFolder=4 'Outbox
olFolder=5 'Sent Items
olFolder=6 'Inbox
olFolder=9 'Calendar
olFolder=10 'Contacts
olFolder=11 'Journal
olFolder=12 'Notes
olFolder=13 'Tasks



'Mail sending
Dim objOutlook
Set objOutlook = CreateObject("Outlook.Application")
Set EMail = objOutlook.CreateItem(0)

SendTO="……. @......com"
SendCC="……. @......com"
sendBCC="……. @......co.in"
MailSubject="Outlook automation"
EMailBodyStr = "Out Look automation body with QTP"
EMail.to=SendTO
EMail.CC=SendCC
EMail.BCC=sendBCC
EMail.Subject=MailSubject
EMail.body=emailBodyStr
EMail.Attachments.Add("C:\SPQTP.txt")
email.Send
objOutlook.quit
Set EMail=Nothing
Set objOutlook=Nothing

In some systems we will get following error
“A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this?”


We can handle this error with installing one third party tool in our machine. Please see the details in the below URL.

http://www.contextmagic.com/express-clickyes

If you want more details for above error refer the following sites.

http://www.add-in-express.com/docs/outlook-security-manager-addins.php

http://pubs.logicalexpressions.com/pub0009/LPMArticle.asp?ID=604

No comments:

Post a Comment