Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending emails from QTP
#1
Solved: 11 Years, 3 Months, 4 Weeks ago
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"


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
Reply
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi,

I had used Outlook to send the mail.Use the below code for reference if its useful 2 u:

Code:
call sendmail("sshukla12@gmail.com","Test Mail","This is a test mail")


Function sendmail(mailto,subject,body)
   Set oMailobj=CreateObject("Outlook.Application")
   Set oSendmailobj=oMailobj.CreateItem(0)
   oSendmailobj.To=mailto
   oSendmailobj.Subject=subject
   oSendmailobj.Body=body
   oSendmailobj.Send
   Set oMailobj=Nothing
   Set oSendmailobj=Nothing
End Function


Regards,
Sankalp
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi Sankalp,

Thanks for your reply.

It is working fine when I am using CreateObject("Outlook.Application"). But when I use CreateObject("CDO.Message") same error "The transport failed to connect to the server" is displayed when oMessage.Send is called.

Do I need to make any settings in my machine when using CreateObject("CDO.Message")?
Do we need to set up Outlook for this to work?

Thanks,
Akhila V
Reply
#4
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi Akhila,

I had not used CDO.message, ya but for the code that i suggested u have 2 use outlook...let me have a look on CDO.message and then only I can reply 2 u on that. Till then any memeber in forum who have idea over this might help u.

Regards,
Sankalp
Reply
#5
Solved: 11 Years, 3 Months, 4 Weeks ago
Try this...
Code:
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="from mail address"
myMail.To="to mail address"
myMail.TextBody="This is a message."
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
="smtp.server.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
=25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
Reply
#6
Solved: 11 Years, 3 Months, 4 Weeks ago
Hello

Please make sure SMTP server is setup perfectly . If you are using Windows 7 then i am sure it will problem. Just setup SMTP correctly. it will work. this is standard code for all the email using SMTP. it is working correctly at my end.

Google search term " SMTP configuration windows 7" or replace windows 7 with your operating system.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending json file request and validating response in soap UI tool using Groovy script smiley 0 3,884 07-19-2017, 04:58 PM
Last Post: smiley
  How to keep recipients in bcc while sending e-mail using QCUtil.QCConnection.SenMail Surya 0 1,988 01-12-2013, 07:05 PM
Last Post: Surya
  Subject line of QC emails beejfred 0 1,949 05-09-2012, 10:32 PM
Last Post: beejfred
  Error while sending email via outlook reejais 2 5,148 02-09-2011, 11:48 AM
Last Post: ksrikanth2k9
  Regarding Email sending from one user to another -Important urgent siri 3 2,641 10-15-2009, 04:38 PM
Last Post: Saket

Forum Jump:


Users browsing this thread: 1 Guest(s)