06-19-2012, 07:13 PM
Hi,
I am trying to send an email from QTP. I called the following function and it displayed an error "The transport failed to connect to the server" when oMessage.Send is called.
Can anyone help me in finding the solution for this
SendCDOMessage "mymail@mail.com", "mymail@mail.com","Hi","Hi this a mail from QTP"
I am trying to send an email from QTP. I called the following function and it displayed an error "The transport failed to connect to the server" when oMessage.Send is called.
Can anyone help me in finding the solution for this
SendCDOMessage "mymail@mail.com", "mymail@mail.com","Hi","Hi this a mail from QTP"
Code:
'''=================================================================
' Function SendCDOMessage
'''=================================================================
' Description:
' Sends an email message using Microsoft's CDO.Message object
' Parameters:
' Return value: True if succeeded, False otherwise
Public Function SendCDOMessage(EmailTo, EmailFrom, EmailSubject, MessageBody)
Dim oMessage
Set oMessage = CreateObject("CDO.Message")
' Set message details
oMessage.Subject = EmailSubject
oMessage.From = EmailFrom
oMessage.To = EmailTo
oMessage.AutoGenerateTextBody = True
oMessage.HTMLBody = MessageBody
' Set configuration
oMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
oMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") =2
oMessage.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465
oMessage.Configuration.Fields.Update
' Send the message
oMessage.Send
MsgBox Err.Number
If Err.Number <> 0 Then
SendCDOMessage = False
Else
SendCDOMessage = True
End If
Set oMessage = Nothing
End Function