Sending Outlook Email with embedded image using VBS

后端 未结 2 2038
慢半拍i
慢半拍i 2020-12-11 07:24

I am currently using the following VBS script to send an email and it works fine, however the image is sent as an attachment. I would instead like to embed the image into t

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 08:22

    I tested this in outlook 2003 and 2016

        'I do have a solution, and that is to convert the Body to HTML
    Dim ToAddress
    Dim FromAddress
    Dim MessageSubject
    Dim MyTime
    Dim MessageBody
    Dim MessageAttachment
    Dim ol, ns, newMail
    MyTime = Now
    
    ToAddress = "email@address.com"
    MessageSubject = "Auto Stats " & MyTime
    ' The trick is to convert all the message body into HTML
    ' Don't mix script text and HTML. Then simply add an HTML image reference.
    ' Remember if the recipient can't get to the image
    ' it won't appear in the email body, and will be blank. So don't use a local image. 
    ' Use an recipient reachable image.
    MessageBody = "Stats Attached" & "

    Produced at " & MyTime & _ "


    " 'MessageAttachment = "P:\stats.png" ! Now Uneccessary Set ol = CreateObject("Outlook.Application") Set ns = ol.getNamespace("MAPI") Set newMail = ol.CreateItem(olMailItem) newMail.Subject = MessageSubject newMail.htmlBody = MessageBody 'Changed the newmMail.Body to newMail.htmlBody newMail.RecipIents.Add(ToAddress) 'newMail.Attachments.Add(MessageAttachment) !This was removed because it would just appear as email attachment newMail.Display

提交回复
热议问题