Micro Focus QTP (UFT) Forums
Outlook question - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Outlook question (/Thread-Outlook-question)



Outlook question - mv8167 - 09-08-2012

Currently I use something like this to send my email (as it has been succesfull for quite some time)

Code:
Set oUtlookApp = CreateObject("Outlook.Application")
Set newMail = oUtlookApp.CreateItem(0)
newMail.Subject = strSubject
newMail.Body = strMessageBody
newMail.To = strMailID_TO
newMail.CC = strMailID_CC
newMail.BCC = strMailID_BCC

If SendResultsInEmailMessage = 1 Then
        If strAttachment <> "" Then
                WScript.Sleep (3000) 'Wait(3)
                newMail.Attachments.Add (strAttachment)
        Else                  
                Exit Function
        End If                
        On Error Resume Next
End If

WScript.Sleep (3000) 'Wait(3)
newMail.Display            'Displays e-mail message window
WScript.Sleep (3000) 'Wait(3)
newMail.Send

Set nAmeSpace = Nothing
Set oUtlookApp = Nothing

Rescently i noticed that my emails are not being sent until I open Outlook.

So I added:
Code:
systemUtil.Run "OUTLOOK.EXE"

now i get 2 emails sent. If Outlook is open, i end up having two Outlook apps open.

Should not my original code just send my email without having to open Outlook?


RE: Outlook question - freeboynil - 09-09-2012

This code worked for me when outlook is opened.

Code:
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0) 'MailItem
With MyItem
.To = "a@a.com"
.Subject = "test"
.ReadReceiptRequested = False
.HTMLBody = "A new project has been created!"
'.display
'SendKeys "%{s}", True
'Type alt+micEnter

.Attachments.Add("c:\test1.txt")
.Send

End With