Solved

Using image tags to embed an image into an Outlook email

Posted on 2010-09-12
10
784 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
ID: 33657235
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
 

Author Comment

by:murbro
ID: 33657413
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
 
LVL 5

Expert Comment

by:Mechanic_Kharkov
ID: 33657589
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:ghemstrom
ID: 33657878
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
 

Author Comment

by:murbro
ID: 33680318
Please could someone give the code needed  in the code I supplied above to make this happen
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33702547
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
 

Author Comment

by:murbro
ID: 33702612
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
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 33702692
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
 

Author Closing Comment

by:murbro
ID: 33702754
Thanks very much once again. Appreciate the help
0
 
LVL 76

Expert Comment

by:David Lee
ID: 33702777
You''re welcome.  Always happy to be of service.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question