Solved

Using image tags to embed an image into an Outlook email

Posted on 2010-09-12
10
780 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
  • 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now