Tuesday, May 26, 2009

Sending Mail from QTP using OutLook

Sending Mail from QTP using OutLook

By Navneesh Garg
As a generic Automation requirement most of the projects look at automatic emails being sent after QTP script executes or ends in a failure. Generally, outlook is configured on the systems on whissing Outlook from QTP.

‘*******************************************************************************
‘ Function: Outlook_SendEmail

‘ Sends an email using Outlook.

‘ Input Parameters:

‘ strTo - The email address or Outlook contact to whom the email should be sent.
‘ strSubject - The email’s subject.
‘ strBody - The email’s body (this may of course include newline characters).

‘ Output Parameters:

‘ None.

‘ Returns:

‘ Not applicable. This is a sub, not a function.

Sub Outlook_SendEmail(strTo, strSubject, strBody)
‘TODO: maybe add support for CC, BCC, etc?

‘Create an Outlook object
Dim Outlook ‘As New Outlook.Application
Set Outlook = CreateObject(”Outlook.Application”)

‘Create a new message
Dim Message ‘As Outlook.MailItem
Set Message = Outlook.CreateItem(0)
With Message
‘You can display the message To debug And see state
‘.Display

.Subject = Subject
.Body = TextBody

‘Set destination email address
.Recipients.Add (strTo)

‘Set sender address If specified.
‘Const olOriginator = 0
‘If Len(aFrom) > 0 Then .Recipients.Add(aFrom).Type = olOriginator

‘Send the message
.Send
End With
End Sub


http://www.qacampus.com
http://www.crestech.in
http://www.crestechsoftware.com.au

No comments: