Is sending email from UFT possible?
Question ID: 106672
1
0

I need to send emails from UFT. Has anyone made/found code that can do this?

Marked as spam
Posted by (Questions: 387, Answers: 66)
Asked on January 29, 2016 10:28 pm
375 views
Answers (1)
1
Private answer

This can be done. I have included some code below that sends an email from a gmail account (these settings should work for any gmail account). Settings for your specific SMTP server will be different. You can find information on the different available settings here: [https://msdn.microsoft.com/en-us/library/ms526318%28v=exchg.10%29.aspx][1]

MyResult = SendCDOMessage(''myemail@someplace.com'', ''mygmail@gmail.com'', ''Email Subject!'', ''Email Body!!'')
msgbox MyResult

Public Function SendCDOMessage(EmailTo, EmailFrom, EmailSubject, MessageBody)
Set oEmail = CreateObject(''CDO.Message'')

' Set message details
oEmail.Subject = EmailSubject
oEmail.Sender = EmailFrom
oEmail.From = EmailFrom
oEmail.To = EmailTo
oEmail.AutoGenerateTextBody = True
oEmail.HTMLBody = MessageBody

' Set configuration
oEmail.Configuration.Fields(''http://schemas.microsoft.com/cdo/configuration/smtpusessl'') = True
oEmail.Configuration.Fields(''http://schemas.microsoft.com/cdo/configuration/smtpauthenticate'') = 1
oEmail.Configuration.Fields(''http://schemas.microsoft.com/cdo/configuration/sendusername'')= EmailFrom
oEmail.Configuration.Fields(''http://schemas.microsoft.com/cdo/configuration/sendpassword'') = ''SetecAstronomy''
oEmail.Configuration.Fields(''http://schemas.microsoft.com/cdo/configuration/smtpserver'') = ''smtp.gmail.com''
oEmail.Configuration.Fields(''http://schemas.microsoft.com/cdo/configuration/sendusing'') = 2
oEmail.Configuration.Fields(''http://schemas.microsoft.com/cdo/configuration/smtpserverport'') = 465

oEmail.Configuration.Fields.Update
' Send the message
oEmail.Send

If Err.Number <> 0 Then
SendCDOMessage = False
Else
SendCDOMessage = True
End If
Set oMessage = Nothing

End Function

[1]: https://msdn.microsoft.com/en-us/library/ms526318%28v=exchg.10%29.aspx

Marked as spam
Posted by (Questions: 17, Answers: 807)
Answered on January 29, 2016 10:29 pm
0
That's really great! Thanks!!
( at January 29, 2016 10:30 pm)
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top