使用QTP从Outlook发送邮件

时间:2015-09-01 05:45:10

标签: outlook qtp

我有一段代码:

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

myMail.To = "sandeep_raulo@infosys.com"
myMail.Subject = "Happy Birthday"
myMail.Body= "Happy Birthday"


myMail.Send
Wait(3)

Set myMail = Nothing
Set objOutlook = Nothing

我想在邮件正文中添加一些图片。

1 个答案:

答案 0 :(得分:1)

试试这段代码。

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

myMail.To = "sandeep_raulo@infosys.com"
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  

在这里,您将电子邮件正文起草为html正文并在其中嵌入图像。