Solved

Using image tags to embed an image into an Outlook email

Posted on 2010-09-12
10
786 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:Murray Brown
[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:Murray Brown
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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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:Murray Brown
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:Murray Brown
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:Murray Brown
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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

695 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