01-23-2008, 02:17 AM
hello,
Basically, you have three choices for scripting emails from QTP;
1. Have QTP access a PHP script that has email functionality.
2. Have QTP use outlook objects to send email.
3. Have QTP create an email object without either of the above.
The first method works, if you can create a PHP page with a script mailer. The downside is, that it uses an web page, but it is effective.
The second method is not ideal, in my opinion. What if the PC you are executing the script on does not have outlook installed? What if the outlook isnt configured with an account? (Bad idea).
The third option seems to be the best and has worked out wonderfully. Sample function code bleow:
'**************** Send Email Function *****************************
Hope this helps,
Chris
Basically, you have three choices for scripting emails from QTP;
1. Have QTP access a PHP script that has email functionality.
2. Have QTP use outlook objects to send email.
3. Have QTP create an email object without either of the above.
The first method works, if you can create a PHP page with a script mailer. The downside is, that it uses an web page, but it is effective.
The second method is not ideal, in my opinion. What if the PC you are executing the script on does not have outlook installed? What if the outlook isnt configured with an account? (Bad idea).
The third option seems to be the best and has worked out wonderfully. Sample function code bleow:
'**************** Send Email Function *****************************
Code:
Function SendMail(EmailAddress, MessageBody, MsgAttachment)
Dim objMessage
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "QTP Results - Automated Testing"
objMessage.From = "QTPTesting@address.com" ' Change this for your own from address
objMessage.To = EmailAddress
objMessage.TextBody = MessageBody
' ==Include File attachments here ==
objMessage.AddAttachment MsgAttachment
'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'==Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "<Server Address Here>" ' "someserver.domain.com"
'==Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
End Function
Hope this helps,
Chris