Using image tags to embed an image into an Outlook email

Hi

I was given the code below to insert html into the body of a message.
That works well but I want to insert an image in a folder instead of just text
using image tags. Something like  "<img .../><img .../><img .../>"
What code would I use to specify two images from different  folders?
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties

    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    'Create e-mail item
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
       'Set body format to HTML
       .BodyFormat = olFormatHTML
       .HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY>Please enter the message text here. </BODY></HTML>"
      

       .Display
    End With

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
David LeeConnect With a Mentor Commented:
That may not work right, but you can certainly try.  Something like this should do it:

<img src=""" & MYPIC_DIR & "image1"" />

You also need to add a backslash to the end of MYPIC_DIR.
0
 
Mechanic_KharkovCommented:
Images in HTML part of mail message can be inserted as external links. You can not send folders via email. =(
You can attach files to email message, but no folders.
And how to embed external link to HTML is not a miracle. (e.g. look source of EE notification email message.html - it contents images).
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi. I don't want to email folders. As I said above I want to send an image as the html body of the message. I want the code to take this image from a specific folder.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Mechanic_KharkovCommented:
Not sure, but it seems that you should gig to Attachments property of mail Item.
Something like that:

    objMail.Save
    Set myAttachments = objMail.Attachments
    myAttachments.Add "C:\My Documents\Q496.jpg", _
      MyAttachType, MyPosition, "Text replacement of attachment"
   
where MyAttachType is [optional] type of attach (maybe "image/jpeg"), and MyPosition is the position of attach in message body. (0 = hidden, 1 - Before the text, and so on).

Details in MSDN
http://msdn.microsoft.com/en-us/library/aa220070%28v=office.11%29.aspx
and
http://msdn.microsoft.com/en-us/library/aa210901%28v=office.11%29.aspx

Not sure how to calc position in the body when it's in HTML format. But MS tells that BodyFormat can be changed from RTF to HTML and vice versa in any time.
Maybe it's possible to obtain each attachment Id to use it in IMG SRC tag of HTML using Attachments(n) construction.
0
 
ghemstromCommented:
I read it that you want to have something similar to a tag in a web page, where you just click the tag to obtain the full-size image. I cannot see that it is possible to hide a full-size image in an html message - but you could do it the same way: You create a tag that you insert into the message as a small-size picture. The tag you link to the full/size image in a public location just as you would do for the web-page.
If the purpose is to distribute images you might automate this with a script that asks you to browse for the image and inserts it automatically.
If you just want to have a single to a couple of  these images you might create "Outlook templates" from email messages (Save as "Outlook template (.oft)) for the different messages, or a Draft, where you create all your Tags with attached links. When you copy the tag to your message the link goes with it.
The tag you create from a copy of  the full-size image that you shrink in e. g. Microsoft Office Picture Manager to a convenient size. You insert the tag into your email message and insert the URL address to the public location into a hyperlink attached to the tag.
To make a good script you might make a VB macro including browsing for the image in the file system and programmatic generation of html code to be inserted into the message just like Mechanic_Charkov (¿¿¿¿¿¿¿_¿¿¿¿¿¿) advices.
 
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Please could someone give the code needed  in the code I supplied above to make this happen
0
 
David LeeCommented:
Hi, murbro.

This should do it. You'll need to edit the URLs of the images and position them as you need them.
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties

    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    'Create e-mail item
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
       'Set body format to HTML
       .BodyFormat = olFormatHTML
       .HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2>" _
                 & "<BODY>Please enter the message text here." _
                 & "<img src=""http://www.company.com/image1"" />" _
                 & "<img src=""http://www.company.com/image2"" />" _
                 & "</BODY></HTML>"
      

       .Display
    End With

Open in new window

0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi. Thanks very much. How do I specify the image source as a folder on my computer.
The images are in the folder
MYPIC_DIR = Environ("userprofile") & "\my documents\Pictures"
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much once again. Appreciate the help
0
 
David LeeCommented:
You''re welcome.  Always happy to be of service.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.