liorde Honored Contributor.
Honored Contributor.
2716 views

UFT send mail through code

Jump to solution

Hi,

Been trying to do this with UFT 14.02. On 12.52 version I had this code working...

This is what I have tried and the results...:

Set objSession = CreateObject("mapi.session")  ->  "ActiveX component can't create mapi.session"

Set Mailer = CreateObject("OSSMTP.SMTPSession") ->  "ActiveX component can't create OSSMTP.SMTPSESSION"

What gives..?

Any other straight forward way to implement this mail sending via UFT ??

 

0 Likes
1 Solution

Accepted Solutions
Knowledge Partner
Knowledge Partner

Re: UFT send mail through code

Jump to solution

I'm assuming you don't have Outlook on your execution machine?

Set MyEmail=CreateObject("CDO.Message")

MyEmail.Subject="UFT Results"
MyEmail.From="VM@domain.com"
MyEmail.To="USER@domain.com"
MyEmail.TextBody="Test123 - Passed"

MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2

'SMTP Server
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"

'SMTP Port
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 

'SMTP Auth (For Windows Auth set this to 2)
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
'Username
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername")="username" 
'Password
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword")="password"

MyEmail.Configuration.Fields.Update
MyEmail.Send

set MyEmail=nothing

Mark Smith

0 Likes
9 Replies
Knowledge Partner
Knowledge Partner

Re: UFT send mail through code

Jump to solution

I'm assuming you don't have Outlook on your execution machine?

Set MyEmail=CreateObject("CDO.Message")

MyEmail.Subject="UFT Results"
MyEmail.From="VM@domain.com"
MyEmail.To="USER@domain.com"
MyEmail.TextBody="Test123 - Passed"

MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2

'SMTP Server
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"

'SMTP Port
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 

'SMTP Auth (For Windows Auth set this to 2)
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
'Username
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername")="username" 
'Password
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword")="password"

MyEmail.Configuration.Fields.Update
MyEmail.Send

set MyEmail=nothing

Mark Smith

0 Likes
Tal Halperin Super Contributor.
Super Contributor.

Re: UFT send mail through code

Jump to solution

Lior, Hi.

Try this: 

https://admhelp.microfocus.com/uft/en/14.02/CodeSamplesPlus_Help/Default.htm#Code_Samples_Plus/CSP_MicrosoftOutlook.htm

This file can be found also as part of other code samples that are part of your UFT installation... look under your machine's Start menu --> UFT --> Documentation --> "UFT Testing Code Samples Plus".

I haven't tried these for a while but these should get you started much faster.

Let me know if there is anything else needed.

Good luck!

 

0 Likes
liorde Honored Contributor.
Honored Contributor.

Re: UFT send mail through code

Jump to solution

Hello Mark and thanks for the reply.

What are these for? Do I need to provide the WindowsNT login info here? 

'Username
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername")="username" 
'Password
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword")="password"

 

 

What is this paameter used for:

smtpauthenticate??

 

0 Likes
liorde Honored Contributor.
Honored Contributor.

Re: UFT send mail through code

Jump to solution

Mark...

Just checked this.

I get a failure on the SEND command, right at the end of the code , error is..:

    "The server rejected the sender address. The server response was: 530 5.7.1 Client was not authenticated"

Client...?? or User ???

0 Likes
Knowledge Partner
Knowledge Partner

Re: UFT send mail through code

Jump to solution

Your mail server does authentication check on the sender email (which most smtp servers do) Have you used your own email address?

Mark Smith.

0 Likes
liorde Honored Contributor.
Honored Contributor.

Re: UFT send mail through code

Jump to solution

OK friends.

 

I finally got it to work.

Yes, Outlook is actually installed on my machine, which makes me think, will this function of mine work, if I were to run this on a remote server with any outlook client.

Thank-you very much for the help ..!

 

 

0 Likes
maheshmohanty
New Member.

Re: UFT send mail through code

Jump to solution

Hi,

Attchments is not working though, have tried  below.

myMail.Attachments.Add("C:\UFT_ALM_TestFramework_GST\UFT_ALM_TestFramework\Test_Results\TestCasesStatus.csv"

 

0 Likes
maheshmohanty
New Member.

Re: UFT send mail through code

Jump to solution

Now its fixed.

MyEmail.AddAttachment("C:\UFT_ALM_TestFramework_GST\UFT_ALM_TestFramework\Test_Results\TestCasesStatus.csv")

0 Likes
Highlighted
liorde Honored Contributor.
Honored Contributor.

Re: UFT send mail through code

Jump to solution

Hi Mark,

I would like to enhacne this question and ask if there is a possibility to send an ATTACHMENT file through this email message ??

What do you think ?

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.