Using Microsoft Outlook to Send Email

The code below illustrates two methods for sending email using the VBScript code in UFT, and two different COM objects. The following examples can be found in SendingEmail.vbs file located in the <UFT installation folder>\CodeSamplesPlus folder.

' Example 1
Function SendMail(SendTo, Subject, Body, Attachment)
	Set ol=CreateObject("Outlook.Application")
	Set Mail=ol.CreateItem(0)
	Mail.to=SendTo
	Mail.Subject=
	Mail.Body=
	If (Attachment <> "") Then
		Mail.Attachments.Add(Attachment)
	End If
	Mail.Send
	ol.Quit
	Set Mail = Nothing
	Set ol = Nothing
End Function

' Example 2
Function SendMail(SendFrom, SendTo, Subject, Body)
	Set objMail=CreateObject("CDONTS.Newmail")
	ObjMail.From = SendFrom
	ObjMail.To = SendTo
	ObjMail.Subject = Subject
	ObjMail.Body = Body
	ObjMail.Send
	Set objMail = Nothing
End Function