Sandeep Raulo
Sandeep Raulo

Reputation: 154

Send mail from Outlook using QTP

I have a piece of code:

Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set myMail = objOutlook.CreateItem(0)

myMail.To = "[email protected]"
myMail.Subject = "Happy Birthday"
myMail.Body= "Happy Birthday"


myMail.Send
Wait(3)

Set myMail = Nothing
Set objOutlook = Nothing

I want to add some pictures in the mail body.

Upvotes: 0

Views: 1163

Answers (1)

ManishChristian
ManishChristian

Reputation: 3784

Try this code.

Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set myMail = objOutlook.CreateItem(0)

myMail.To = "[email protected]"
myMail.Subject = "Happy Birthday"
strBody = "<p>Happy Birthday</p>"
strBody = strBody & "<img src='Your Image Path' alt='Some name (optional)' width='Some Width' height='Some Height'>"
'For example: "<img src='Your Image Path' alt='XYZ' width='50' height='50'>"

myMail.HTMLBody = strBody

myMail.Send
Wait(3)

Set myMail = Nothing
Set objOutlook = Nothing  

Here you are drafting email body as html body and embedding an image in it.

Upvotes: 1

Related Questions