UFT/QTP tutorial – A quick function to send an email using outlook

Hello. Below is an awesome function to send an email using your outlook application. This function will only work with outlook, so make sure you set up your outlook app and account first.

1. Call the function with funSendEmailFromOutlook "qtptutorial.net@gmail.com", "You're Amazing", "Thanks for all these awesome tutorials", "True", "C:\Users\dadovolo\Desktop\AttachmentTest.txt"
The first parameter is the email you want to send it to. The second parameter is the subject line, 3rd parameter is the Body text. And if you want to attach a file, the strAttachTrueFalse should be "True" and the strAddonPath should be the file path of the file you want to attach. If you don't want to attach a file, put an empty string for those two parameters. Ex below:

funSendEmailFromOutlook "qtptutorial.net@gmail.com", "You're Amazing", "Thanks for all these awesome tutorials", "", ""


FUNCTION CODE BELOW

Function fnSendEmailFromOutlook(strReceiverAddress, strSubject, strBody, strAttachTrueFalse, strAddonPath)

'Create an object of type Outlook
Set objOutlook = CreateObject("Outlook.Application")
Set myMail = objOutlook.CreateItem(0)

'Set the email properties
myMail.To = strReceiverAddress
myMail.Subject = strSubject
myMail.Body= strBody

If strAttachTrueFalse = "True" Then
myMail.Attachments.Add(strAddonPath)
End If

'Send the mail
myMail.Send
Wait 3

'Clear object reference
Set myMail = Nothing
Set objOutlook = Nothing

End Function

 


Function funSendEmailFromOutlook(strReceiverAddress, strSubject, strBody, strAddonPath)

'Create an object of type Outlook
Set objOutlook = CreateObject("Outlook.Application")
Set myMail = objOutlook.CreateItem(0)

'Set the email properties
myMail.To = strReceiverAddress
myMail.Subject = strSubject
myMail.Body= strBody
myMail.Attachments.Add(strAddonPath)

'Send the mail
myMail.Send
Wait 3

'Clear object reference
Set myMail = Nothing
Set objOutlook = Nothing

End Function

Pin It on Pinterest

Clef two-factor authentication