How do we send email from QTP ?

We can send an email from a QTP testscript by using the below function. It uses CDO.Message object to perform that action. We use the SMTP Server to deliver the email message to the concerned email ID. Please update the values as per your environment. This function sends a email attachment to specified email address.

Call this function as

sendEmail(“c:\testreport.txt”, “myemail@mycompany.com”)

Function sendEmail(reportfile,sendto)

Set oMessage = CreateObject(“CDO.Message”)

‘==This section provides the configuration information for the remote SMTP server.
‘==Normally you will only change the server name or IP.
oMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2

‘Name or IP of Remote SMTP Server
oMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “Your_smtp_server_name”

‘Server port (typically 25)
oMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25

oMessage.Configuration.Fields.Update
oMessage.Subject = “Specify the subject here”
oMessage.Sender = “Your email ID”
oMessage.To = sendto
oMessage.CC = “an email ID”
oMessage.TextBody = “Please find the report attached” &vbcrlf & vbcrlf & “Thanks” & vbcrlf & “your name”
oMessage.AddAttachment reportfile
oMessage.Send

Set oMessage = Nothing

End Function

9 thoughts on “How do we send email from QTP ?

  1. Hi,
    Need your help, how do i convert a batch of qtp test results into excel and send via email automatically to eg. managers.?

  2. Hi Hari,

    This document looks good.
    I have a doubt here.
    i have configured outlook in my system.
    in the place of ‘Your_smtp_server_name’ , what i need to put?

  3. Hi Hari,

    Do you have the same type of information for reading mails from a pop server.

    Now I’m able to send mail but not to read them thru my pop connection.

    thanks in advance

Leave a comment